[Image-SIG] PIL and simple conversion

Scott David Daniels Scott.Daniels at Acm.Org
Mon Dec 1 19:08:08 CET 2008


Gregory Tappero wrote:
> Hi everyone, ...
> So far i did this:
>     im = Image.open("foo.png")
>     ...
>     im.save("new2.png", transparency=0)
> it works well, except that i dont want to save the image i want the
> data to return it to my web client.
> So what is a equivalent of im.save("new2.png", transparency=0) which
> does not save the image ?

Almost a FAQ:

     import cStringIO
     import Image

     im = Image.open("xyzzy.png")
     ...
     holder = cStringIO.StringIO()
     im.save(holder, format="png", transparency=0)
     bytes_string = holder.getvalue()

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Image-SIG mailing list