[Image-SIG] Image.tostring method

Fredrik Lundh fredrik@pythonware.com
Sun, 15 Oct 2000 13:58:23 +0200


jeff wrote:
> I'm trying to use the Image.tostring method to spit out data for a gif
> image I have generated in a script.  I can successfully use
> Image.save('blah.gif') to create a gif, but would like to be able to
> store this data in memory and eventually shove it into a web page - sans
> file.  Does anyone have an example call (with args for the encoder).

"tostring" only gives you the image data, not a complete file
(codecs and file format handlers are two different things in
PIL)

to do what you want, use the "save" method, and save to a
StringIO object:

    file = StringIO.StringIO()
    im.save(file, "GIF")
    data = file.getvalue()

hope this helps!

</F>