473,385 Members | 1,764 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,385 software developers and data experts.

PIL: how to return a StringIO of an Image

Hi,

I have a script I pass (from Zope) an image file to, to do some PIL image stuff
with it. I want a StringIO instance representing the altered image file to be
returned. What is the method to get the image data (header and pixel data)? I
tried Image.tostring(), but that only returns the pixle data. But to be able to
use the returned data in Zope as an image file (manage_addImage, in case someone
cares), I need the complete representation of the. file.

Here’s some code:

def modify_image(self, my_image):
from PIL import Image
from StringIO import StringIO

image=Image.open(my_image)
. # do some PIL
Jul 18 '05 #1
5 15169
"Christoph" wrote:
image.save('test', 'JPEG')
image=StringIO(image.????()) # what's the right method?
return image

Any hints? Thanx!


file = StringIO()
image.save(file, "JPEG")
return file.getvalue()

</F>


Jul 18 '05 #2
Fredrik Lundh schrieb:
image.save('test', 'JPEG')
image=StringIO(image.????()) # what's the right method?
return image

Any hints? Thanx!

file = StringIO()
image.save(file, "JPEG")
return file.getvalue()

That's what I wanted. Perfect!
Thanx a lot!
Christoph

Jul 18 '05 #3
On Fri, 14 Nov 2003 16:45:39 +0100, "Fredrik Lundh" <fr*****@pythonware.com> wrote:
"Christoph" wrote:
image.save('test', 'JPEG')
image=StringIO(image.????()) # what's the right method?
return image

Any hints? Thanx!


file = StringIO()
image.save(file, "JPEG")
return file.getvalue()

You are recommending shadowing 'file' ?!

Regards,
Bengt Richter
Jul 18 '05 #4
JCM
Bengt Richter <bo**@oz.net> wrote:
On Fri, 14 Nov 2003 16:45:39 +0100, "Fredrik Lundh" <fr*****@pythonware.com> wrote:

"Christoph" wrote:
image.save('test', 'JPEG')
image=StringIO(image.????()) # what's the right method?
return image

Any hints? Thanx!


file = StringIO()
image.save(file, "JPEG")
return file.getvalue()

You are recommending shadowing 'file' ?!


Why not? Python is a block-structured language. New builtins can
arrive in any release.
Jul 18 '05 #5
On Fri, 14 Nov 2003 20:38:43 +0000 (UTC), JCM <jo******************@myway.com> wrote:
Bengt Richter <bo**@oz.net> wrote:
On Fri, 14 Nov 2003 16:45:39 +0100, "Fredrik Lundh" <fr*****@pythonware.com> wrote:

"Christoph" wrote:

image.save('test', 'JPEG')
image=StringIO(image.????()) # what's the right method?
return image

Any hints? Thanx!

file = StringIO()
image.save(file, "JPEG")
return file.getvalue()

You are recommending shadowing 'file' ?!


Why not? Python is a block-structured language. New builtins can
arrive in any release.

I'd say a reason is to avoid the time you will do it by habit and get a surprise.
But yes, there's no technical reason you can't, if you don't want to use the original
binding in that scope.

Regards,
Bengt Richter
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Steve Castellotti | last post by:
Hey all-- I have a simple photo website written in python. I would like to be able to use Python Imaging Library (or similar) to read an image file from the disk, resize/thumbnail it in memory,...
1
by: Raaijmakers, Vincent (IndSys,GE Interlogix) | last post by:
In my application I would like to convert a JPG to a PNG format. Easy, if you save the output to a file. image.save('file.png', 'PNG') Now, this is not what I want. In my application I would...
0
by: KK | last post by:
Hallo. I have Zope 2-7-0 on Linux platform and the following problem :) I'm sending an image through form on the pythonScript. I want script to resize image and save on the zope folder in 3...
4
by: Almad | last post by:
Hello, I wonder how do I create reasonable thumbnails from JPEG with PIL. My code: logging.debug('Downloading image %s' % id) uri = ''.join(, '?p=', str(id)]) uf = urlopen(uri).read() f =...
2
by: Odalrick | last post by:
I'm making a simple program to crop and scale images, essentially make thumbnails from a user defined subset of the image. I'm planning to use Python Image Library to crop and resize the images,...
2
by: Craig | last post by:
Hi there, I'm trying to open colour BMPs using PIL and I'm getting the following errors. Opening a 16 colour BMP I get: Traceback (most recent call last): File "<pyshell#3>", line 1, in...
4
by: cyberco | last post by:
I'm using web.py to send an image to the client. This works (shortened): print open(path, "rb").read() but this doesn't: img = Image.open(path) img.thumbnail((10,10)) print img.getdata()
0
by: Jair Trejo | last post by:
I'm doing some image processing in PIL, and I want to display the results in a GTK window using PyCairo, so I create a Cairo image surface from the PIL Image like this: mfile =...
1
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...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.