[Image-SIG] convert in memory jpg to bmp
Fredrik Lundh
fredrik at pythonware.com
Wed Jul 12 23:18:44 CEST 2006
Roman Petrichev wrote:
> I've got such the problem. I have a function processing bmp images given
> to it as a parameter. For example:
>
> img_data = open('1.bmp').read()
> result = my_func(img_data)
>
> it works fine. The point is how to do the same with a jpg image. my_func
> works only with bmp data. So I've to convert file into bmp. From PIL doc
> I got to know how to do this, but I don't want to save file into bmp
> image - I want to have bmp data in memory.
> How can I do this?
open the image as usual, and save it to a StringIO object:
http://docs.python.org/lib/module-StringIO.html
e.g.
im = Image.open('1.jpg')
f = StringIO.StringIO()
im.save(f, "BMP")
result = my_func(f.getvalue())
</F>
More information about the Image-SIG
mailing list