[Image-SIG] Image.tostring method

kcaza@cymbolic.com kcaza@cymbolic.com
Fri, 13 Oct 2000 12:55:44 -0700

Image.tostring() does not give you a string representation of a GIF image... it
gives you the image data itself, pixel for pixel.

If you want to format that into a GIF file, you'll have to do it some other way.
I'd suggest either saving it as a GIF normally, the reading it back in from that
file as a binary stream, or finding a way of capturing the Image .save function
to memory instead of disk.


Jeff Simpson <jeffrey.simpson@supplysolution.com> on 10/13/2000 12:29:40 PM

To:   image-sig@python.org
cc:    (bcc: Kevin Cazabon/cymbolic/gig)

Subject:  [Image-SIG] Image.tostring method

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).
Here is what I've been using for Image.tostring:

....some steps to create the image with RGBA mode skipped
# Now I wanna get the str data
>>> data = im.tostring('gif', 'RGBA')
>>> im.save(blah_a.gif')
>>> fd = open('blah_b.gif', 'w')
>>> fd.write(data)
>>> fd.close()

blah_a, generated from Image.save is happy and I can viedw it with xv.
blah_b, generated with Image.tostring is bogus.  I'm a little confused
as to what needs to be passed to the encoder to make it work correctly.


Image-SIG maillist  -  Image-SIG@python.org