[Zope] PIL: convert an image-object back to file object

Christoph Landwehr chris-zopemailing at gmx.de
Fri Nov 14 06:52:23 EST 2003


Thanx Jens and Dieter for the hint that manage_addImage allows string input.

Jens Vagelpohl schrieb:
>> In the script I want to save the returned object as an Zope image 
>> object using manage_addImage(). But the manage_addImage method expects 
>> a file object, not a PIL.Image.Image.
> 
> Save the PIL Image into an intermediary cStringIO instance and pass that 
> one into manage_addImage.

Somehow I seem to pass the wong data to StringIO:

image=StringIO(my_PIL_image.tostring())
returns me a StringIO instance of the Object.

However I don't get valid image data:

self.manage_addImage('foo', image, title='bar', content_type='image/jpeg')
adds an object to Zope with about the right filesize but I can not viw the 
image: view returns the string 'bar'

Is the PIL Image method tostring() the right choice?

Regards
Christoph




More information about the Zope mailing list