python image library making dotty gifs

Oliver Fromme olli at haluter.fromme.com
Fri Jun 25 08:11:44 EDT 2004


Alex Hunsley <lard at tardis.ed.ac.molar.uk> wrote:
 > I'm using python image library 1.1.4 (http://www.pythonware.com/products/pil/) 
 > to plot images.
 > However, when I save an image to a gif file, it comes out very dotty/ithered 
 > looking, even if it's a picture consisting only of one colour!
 > [...]
 > im = Image.new("RGB", (imageWidth, imageHeight))
 > [...]
 > im.save("plotImage.gif", "GIF")

You're creating an RGB image (i.e. 24 bits per pixel), and
then you're saving it to a GIF file which can handle only
8 bits per pixel.  The GIF file format uses a so-called
palette to map 24bit RGB colors to 8 bits.  You haven't
defined any palette, so I guess it's using a default one,
to which it has to convert your image, obviously involving
dithering.

I'm not a PIL user, so I can't tell you how to define your
own optimized palette with it.

Another option would be to save the image in PNG format,
which supports 24bits natively.

Best regards
   Oliver

-- 
Oliver Fromme, Konrad-Celtis-Str. 72, 81369 Munich, Germany

``All that we see or seem is just a dream within a dream.''
(E. A. Poe)



More information about the Python-list mailing list