so here we go. i am currently making a script for myself. it is basically rotating and resizing a number of images. i am just a beginner and i chose python because i might need to make some more scripts, and it is not so hard to learn. so i am just starting the script, and am developing a script that will rotate and resize one image. here is what i have so far: -
import Image
-
im = Image.open("/home/bella/Desktop/LEMONKIWI.jpg")
-
out = im.resize((612, 600))
-
out = im.rotate(90) # degrees clockwise
-
im.save(file + ".jpg", "JPEG")
-
i know"
-it doesnt work
- the reason is the last line.
so basically i am asking, what to write for the last line tomake sure that the picture is saved. ?.
a HUGE thank to whoever helps me.
6 3760
so here we go. i am currently making a script for myself. it is basically rotating and resizing a number of images. i am just a beginner and i chose python because i might need to make some more scripts, and it is not so hard to learn. so i am just starting the script, and am developing a script that will rotate and resize one image. here is what i have so far: -
import Image
-
im = Image.open("/home/bella/Desktop/LEMONKIWI.jpg")
-
out = im.resize((612, 600))
-
out = im.rotate(90) # degrees clockwise
-
im.save(file + ".jpg", "JPEG")
-
i know"
-it doesnt work
- the reason is the last line.
so basically i am asking, what to write for the last line tomake sure that the picture is saved. ?.
a HUGE thank to whoever helps me.
Well, you didn't give us much to go on here. For example, I had to deduce from my system that you must be using the PIL extension module.
Your code looks good, except for two mistakes: "file" is not a string, it is a built-in function - use a new filename string there. Saving im instead of out.
I tested this: -
>>> import Image
-
>>> theDir = """C:\Documents and Settings\All Users\Documents\My Pictures\HETAP 2.0\Nevada\Inhouse\Bartly Ranch\practice\4 practice Bartly 2007-07-17"""
-
>>> fName = "Feature@0Ft-00002.jpg"
-
>>> im = Image.open(r'%s\%s' %(theDir, fName))
-
>>> out = im.resize((612, 600))
-
>>> out = im.rotate(90) # degrees clockwise
-
>>> out.save("%s/newPic.jpg" %theDir, 'JPEG')
-
>>>
Rotation worked, but resizing didn't.
Well, you didn't give us much to go on here. For example, I had to deduce from my system that you must be using the PIL extension module.
Your code looks good, except for one mistake: saving im instead of out.
I tested this: -
>>> import Image
-
>>> theDir = """C:\Documents and Settings\All Users\Documents\My Pictures\HETAP 2.0\Nevada\Inhouse\Bartly Ranch\practice\4 practice Bartly 2007-07-17"""
-
>>> fName = "Feature@0Ft-00002.jpg"
-
>>> im = Image.open(r'%s\%s' %(theDir, fName))
-
>>> out = im.resize((612, 600))
-
>>> out = im.rotate(90) # degrees clockwise
-
>>> out.save("%s/newPic.jpg" %theDir, 'JPEG')
-
>>>
Rotation worked, but resizing didn't.
Here's the fix for that last part: -
>>> im = Image.open(r'%s\%s' %(theDir, fName))
-
>>> out = im.resize((612, 600))
-
>>> out = out.rotate(90) # degrees clockwise
-
>>> out.save("%s/newPic.jpg" %theDir, 'JPEG')
-
>>>
Here's the fix for that last part: -
>>> im = Image.open(r'%s\%s' %(theDir, fName))
-
>>> out = im.resize((612, 600))
-
>>> out = out.rotate(90) # degrees clockwise
-
>>> out.save("%s/newPic.jpg" %theDir, 'JPEG')
-
>>>
yes, the saving part worked. do you know anything about why the resizing didnt thougH?. thanks for the help, anyways.
yes, the saving part worked. do you know anything about why the resizing didnt thougH?. thanks for the help, anyways.
It didn't work because you were assigning to out the original image, when you already made changes to out (the resizing). You overrode the resizing with the rotating.
yes, the saving part worked. do you know anything about why the resizing didnt thougH?. thanks for the help, anyways.
Note how many time im is used on the right hand side of the equal sign in each example.
I love PIL and use it on occasion. Let me throw out a couple of examples that don't so much speak directly to your question but illustrate some things I appreciated early on. In this case I have a file called test.tif in my tmp directory. I want to open it, rotate it 45 degrees, resize the result, and display it. In a real program things like resampling modes, and aspect ratios would be considered but this is just to make a point. - Image.open('/tmp/test.tif','r').rotate(45).resize([200,100]).show()
This is why I love this stuff.
Image.open('/tmp/test.tif','r'), creates an open image object, the "im" in most examples.
.rotate(45) , then takes that object and rotates it 45 degrees.
.resize([200,100]) , now the open, rotated object is resized.
Which can then be displayed in the default system viewer by just saying .show().
If I in fact wanted to save that modified image, all I need to do is replace .show() with .save() with the appropriate variables. like... - Image.open('/tmp/test.tif','r').rotate(45).resize([200,100]).save('/tmp/newtest.tif')
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Alper Adatoz |
last post by:
Hi,
i have a little problem. i hope u guys give me a clear solution (:
db: mssql
i just want to put jpeg file to the image field at the mssql db.
and after that i want to call it back..
|
by: Alex Hunsley |
last post by:
I'm using python image library 1.1.4 (http://www.pythonware.com/products/pil/)
to plot images.
However, when I save an image to a gif file, it comes out very dotty/ithered
looking, even if it's a...
|
by: Tompa |
last post by:
Hi,
I would like to create images on the fly as a response to an http request.
I can do this with PIL like this (file create_gif.py):
from PIL import Image, ImageDraw
print 'Status: 200 OK'...
|
by: dale zhang |
last post by:
Hi,
I am trying to read an image from MS Access DB based on the following article:
http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp
The article author is using PictureBox for windows...
|
by: dale zhang |
last post by:
Hi,
I am trying to save and read an image from MS Access DB based on the
following article:
http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp
Right now, I saved images without any...
|
by: Mark Denardo |
last post by:
My question is similar to one someone posted a few months back, but I don't
see any replies.
Basically I want to be able to have users upload photos and save them in a
database (as byte data)...
|
by: bharathv6 |
last post by:
i need to do is modify the image in memory like resizing the image in memory etc ... with out saving it disk as i have to return back the image with out saving it disk
PIL supports the use of...
|
by: Thomas Guettler |
last post by:
Hi,
I tried PIL for image batch processing. But somehow I don't like it
- Font-Selection: You need to give the name of the font file.
- Drawing on an image needs a different object that pasting...
|
by: defn noob |
last post by:
from Tkinter import *
import os
master = Tk()
w = Canvas(master, width=800, height=600)
print os.path.exists('C:/me/saftarn/desktop/images/blob4.jpg')
im = PhotoImage(file =...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |