[Image-SIG] Simple Question, avoid Image.save

Matthew Westcott matthew at west.co.tt
Thu Jan 5 20:21:21 CET 2012


On 29 Dec 2011, at 12:31, auto11436877 at hushmail.com wrote:

> Hi, I wanted to get the actual bmp data without writting the content to disk.
> 
> Example:
> im = Image.new("RGB", (16, 16) )
> im.save('image.bmp')
> 
> I want to avoid im.save, and just get the actual BMP file data for further processing.
> 
> Hope you can help me.

Hi,
The im.save method can accept a file object instead of a filename, which means you can avoid writing to disk by passing it a StringIO object instead:

import StringIO, Image
im = Image.new("RGB", (16, 16) )
io = StringIO.StringIO()
im.save(io, 'bmp')
bmpdata = io.getvalue()


- Matt


More information about the Image-SIG mailing list