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

Andy McCurdy andy at andymccurdy.com
Wed Jan 9 17:32:47 CET 2008


Fredrik, thanks for the reply.  I am in fact converting to "RGB"
first... at least I think so.  Here's the code I'm using that produces
bad results:

from PIL import Image

# io is a file handle
pil_image = Image.open(io)

# convert to rgb
pil_image = pil_image.convert('RGB')

# new_width/new_height are calculated to retain the
# current height/width proportions
new_size = (new_width, new_height)

#resize the image
pil_image = pil_image.resize(new_size, Image.ANTIALIAS)

# save the image back to disk
pil_image.save(io, 'GIF')


On Jan 9, 2008 12:28 AM, Fredrik Lundh <fredrik at pythonware.com> wrote:
> Andy McCurdy wrote:
>
> > Just started using PIL.  I'm attempting to resize a .gif image to a
> > smaller size, keeping the height/width proportional.  The resize
> > works, but the resulting image is very grainy.
>
> try converting the image to "RGB" first, and use resize(ANTIALIAS) on
> the RGB image before converting it back to P.
>
> (if you resize a "P" image as is, you can only use the NEAREST
> resampling method.  this works reasonably well for certain kinds of
> "graphics", but less so for images that are dithered.  for some kinds of
> images, smoothing the RGB image before resizing it might also help.)
>
> </F>
>
> _______________________________________________
> Image-SIG maillist  -  Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig
>


More information about the Image-SIG mailing list