[Image-SIG] Poor Image Quality When Resizing a GIF

Fredrik Lundh fredrik at pythonware.com
Thu Jan 10 08:45:18 CET 2008


Andy McCurdy wrote:

>> Using palette=Image.ADAPTIVE will be better for all images unless the
>> images are already in the web palette, or the viewers are from 1995
>> and have 256 colour displays.  Both of these are unlikely, and in any
>> case the adaptive system will work well enough for them. It will be
>> slower though.
 >
 > Thanks Douglas.  Just tested it out, and the quality has improved
 > dramatically on all GIF images I threw at it.

In addition to Douglas' excellent advice, you should probably also ask 
yourself if you really need to store the thumbnails as GIF images.

For the general case, I'd probably use JPEG for everything (if it's good 
enough for Google, etc).  If you have lots of non-photographic images in 
your database, you can use PNG for things that have 256 colors or less:

     if im.getcolors(256):
         # limited number of colors
         im = im.convert("P", palette=Image.ADAPTIVE, dither=Image.NONE)
         im.save(out, "PNG")
     else:
         im.save(out, "JPEG")

(getcolors returns None if there are more than the given number of 
colors in the image.  you can change 256 to something larger if you want 
to; 512 or 1024 probably works well in practice)

</F>



More information about the Image-SIG mailing list