faqts : Computers : Programming : Languages : Python : Common Problems : Images

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 11 people (64%) answered Yes
Recently 5 of 7 people (71%) answered Yes

Entry

How can I convert a gif image to a bitmap representation of it?

Aug 30th, 2000 21:28
unknown unknown, Greg Landrum


I'm not completely sure what you mean by "bitmap representation", but
PIL probably does what you want.  :-)
To convert to a BMP (windows bitmap), you would do:
>>> from Pil import Image
>>> img = Image.open('foo.gif')
>>> img.save('foo.bmp')
If you would rather get a Numeric array with the values from the image:
>>> from Pil import Image
>>> from Numeric import *
>>> img = Image.open('foo.gif')
>>> arr = resize(fromstring(img.tostring(),Int8),img.size)
I hope this helps.
You can find PIL at URL:
http://www.pythonware.com/products/pil/index.htm