[Image-SIG] image caching using pil

Fredrik Lundh fredrik at pythonware.com
Thu Feb 14 21:10:02 CET 2008

bharath venkatesh wrote:

>    is it possible to cache image , access the image from the cache , 
> modify the  image and store it back in the cache with out having to 
> store the image in disk  using pil.. if so let me know how to do it . 
> otherwise please suggest a alternative ...

assuming "image" means an image stored in an image interchange format 
(e.g. JPEG or PNG etc), use PIL together with the StringIO module:

     from PIL import Image
     from StringIO import StringIO

     data = "... png data ..."

     im = Image.open(StringIO(data))

     out = StringIO()
     im.save(out, format="PNG")
     data = out.getvalue()


More information about the Image-SIG mailing list