473,387 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

image saving in python.

2
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:
Expand|Select|Wrap|Line Numbers
  1. import Image
  2. im = Image.open("/home/bella/Desktop/LEMONKIWI.jpg")
  3. out = im.resize((612, 600))
  4. out = im.rotate(90) # degrees clockwise
  5. im.save(file + ".jpg", "JPEG")
  6.  
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.
Sep 8 '07 #1
6 3760
bartonc
6,596 Expert 4TB
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:
Expand|Select|Wrap|Line Numbers
  1. import Image
  2. im = Image.open("/home/bella/Desktop/LEMONKIWI.jpg")
  3. out = im.resize((612, 600))
  4. out = im.rotate(90) # degrees clockwise
  5. im.save(file + ".jpg", "JPEG")
  6.  
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:
Expand|Select|Wrap|Line Numbers
  1. >>> import Image
  2. >>> theDir = """C:\Documents and Settings\All Users\Documents\My Pictures\HETAP 2.0\Nevada\Inhouse\Bartly Ranch\practice\4 practice Bartly 2007-07-17"""
  3. >>> fName = "Feature@0Ft-00002.jpg"
  4. >>> im = Image.open(r'%s\%s' %(theDir, fName))
  5. >>> out = im.resize((612, 600))
  6. >>> out = im.rotate(90) # degrees clockwise
  7. >>> out.save("%s/newPic.jpg" %theDir, 'JPEG')
  8. >>> 
Rotation worked, but resizing didn't.
Sep 8 '07 #2
bartonc
6,596 Expert 4TB
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:
Expand|Select|Wrap|Line Numbers
  1. >>> import Image
  2. >>> theDir = """C:\Documents and Settings\All Users\Documents\My Pictures\HETAP 2.0\Nevada\Inhouse\Bartly Ranch\practice\4 practice Bartly 2007-07-17"""
  3. >>> fName = "Feature@0Ft-00002.jpg"
  4. >>> im = Image.open(r'%s\%s' %(theDir, fName))
  5. >>> out = im.resize((612, 600))
  6. >>> out = im.rotate(90) # degrees clockwise
  7. >>> out.save("%s/newPic.jpg" %theDir, 'JPEG')
  8. >>> 
Rotation worked, but resizing didn't.
Here's the fix for that last part:
Expand|Select|Wrap|Line Numbers
  1. >>> im = Image.open(r'%s\%s' %(theDir, fName))
  2. >>> out = im.resize((612, 600))
  3. >>> out = out.rotate(90) # degrees clockwise
  4. >>> out.save("%s/newPic.jpg" %theDir, 'JPEG')
  5. >>> 
Sep 8 '07 #3
bel10
2
Here's the fix for that last part:
Expand|Select|Wrap|Line Numbers
  1. >>> im = Image.open(r'%s\%s' %(theDir, fName))
  2. >>> out = im.resize((612, 600))
  3. >>> out = out.rotate(90) # degrees clockwise
  4. >>> out.save("%s/newPic.jpg" %theDir, 'JPEG')
  5. >>> 

yes, the saving part worked. do you know anything about why the resizing didnt thougH?. thanks for the help, anyways.
Sep 9 '07 #4
ilikepython
844 Expert 512MB
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.
Sep 9 '07 #5
bartonc
6,596 Expert 4TB
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.
Sep 9 '07 #6
dshimer
136 Expert 100+
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.

Expand|Select|Wrap|Line Numbers
  1. 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...
Expand|Select|Wrap|Line Numbers
  1. Image.open('/tmp/test.tif','r').rotate(45).resize([200,100]).save('/tmp/newtest.tif')
Sep 11 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
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..
4
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...
5
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'...
3
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...
4
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...
6
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)...
2
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...
6
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...
2
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 =...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.