Resizing Tif's to smaller gifs adds pixels

Samuel smullen.uclick at gmail.com
Tue Oct 21 16:47:37 EDT 2008


Scott,

I appreciate the quick response, but I need this in a GIF format.

Samuel

On Oct 21, 3:46 pm, Scott David Daniels <Scott.Dani... at Acm.Org> wrote:
> smullen.ucl... at gmail.com wrote:
> > ...I need to scale a TIFF image from 1925x588 px to a GIF of 600xnnn px.
> > I've tried the following code, but it leads to a lot of extra odd
> > colored pixels being inserted into the resulting image.
> > img = "tmp/tmsho20080901.tif"
> > im = Image.open("tmp/tmsho20080901.tif")
> > w, h = im.size
> > im.thumbnail((600, h * 600 / w), Image.ANTIALIAS)
>
> This line is rather silly, making a result that you drop on the floor.> newimg = im.resize((600, int(h * (600.0 / w))), Image.ANTIALIAS)
> > newimg.save("tmsho20080901.gif")
>
> ...
>
> > Using ImageMagick's convert I would do this...
>
> > convert -colors 256 -resize 600 -colorspace RGB -black-threshold 100 -
> > contrast -intent Perceptual tmp/tmsho20080901.tif tmsho20080901.gif
>
> > I think it may have something to do with the palette or the number of
> > colors alotted for the resulting image, but I'm really not a graphics
> > guy.
>
> Yep, you are right.  The issue is trying to reduce to a 256-color
> pallette.  Try using '.png' format (portable network graphics), that
> allows a full palette for exact pixel images.
>
> Try something like this:
>      im = Image.open("tmp/tmsho20080901.tif")
>      w, h = im.size
>      im.thumbnail((600, h * 600 // w),
>                   Image.ANTIALIAS).save("tmp/sho20080901.png")
>
> --Scott David Daniels
> Scott.Dani... at Acm.Org




More information about the Python-list mailing list