[Image-SIG] modifying images in memory

bharath venkatesh bharathv6 at gmail.com
Wed Feb 13 12:12:33 CET 2008

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 StringIO objects being passed in place of file
objects.  StringIO objects are binary strings of variable length that are
in memory so i saved the image in stringio objects the following code does
 file = StringIO()
 image.save(file, "JPEG")
cached_image = file.getvalue()
but i  can't apply resize operation on cached_image as it a str object
but i found out that Image.formstring(mode, size, data, decoder, parameters)
Creates an image memory from pixel data in a string so i did the following


but the i got following error shown below  can any one tell me what was the
error .. or tell me an alternative to modify the image in memory with out
saving in disk ..

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 1744, in
    im.fromstring(data, decoder_name, args)
  File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 577, in
    raise ValueError("cannot decode image data")
ValueError: cannot decode image data
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/image-sig/attachments/20080213/431eb343/attachment-0001.htm 

More information about the Image-SIG mailing list