[Image-SIG] create image-instances from data strings

Fredrik Lundh fredrik@pythonware.com
Wed, 18 Oct 2000 13:00:18 +0200


Torsten wrote:
> I try to convert JPEG images from LDAP and put it in an
> ZOPE-Application.

/.../

> Putting the data in an file , using Image.open(), Image.save() an
> finally read the data from the saved file works. But it's not the way I
> want to do that. Perhaps there is a similar way to .open() and .save()
> with using memory data ??

sure: just wrap the data in a StringIO object, and use
Image.open() on that object:

    file = StringIO.StringIO(data)
    image = Image.open(file)

saving to a string is as easy (cf. the recent "Image.tostring" thread)

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

</F>