Resizing Tif's to smaller gifs adds pixels

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • smullen.uclick@gmail.com

    Resizing Tif's to smaller gifs adds pixels

    I'm not entirely sure how this group works: if there is a page I'm
    supposed to follow up on or if I should expect an email in reply.
    Anyway, here's my question.

    I'm very new to Python and PIL, I know how to do this stuff in perl
    and ImageMagick, but I'm having issues with Python and PIL.

    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.t if"
    im = Image.open("tmp/tmsho20080901.t if")
    w, h = im.size

    im.thumbnail((6 00, h * 600 / w), Image.ANTIALIAS )

    newimg = im.resize((600, int(h * (600.0 / w))), Image.ANTIALIAS )
    newimg.save("tm sho20080901.gif ")

    Using ImageMagick's convert I would do this...

    convert -colors 256 -resize 600 -colorspace RGB -black-threshold 100 -
    contrast -intent Perceptual tmp/tmsho20080901.t if tmsho20080901.g if

    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.

    Any help on this would be appreciated.

    Samuel
  • Scott David Daniels

    #2
    Re: Resizing Tif's to smaller gifs adds pixels

    smullen.uclick@ 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.t if"
    im = Image.open("tmp/tmsho20080901.t if")
    w, h = im.size
    im.thumbnail((6 00, 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("tm sho20080901.gif ")
    ....
    Using ImageMagick's convert I would do this...
    >
    convert -colors 256 -resize 600 -colorspace RGB -black-threshold 100 -
    contrast -intent Perceptual tmp/tmsho20080901.t if tmsho20080901.g if
    >
    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.t if")
    w, h = im.size
    im.thumbnail((6 00, h * 600 // w),
    Image.ANTIALIAS ).save("tmp/sho20080901.png ")

    --Scott David Daniels
    Scott.Daniels@A cm.Org

    Comment

    • Samuel

      #3
      Re: Resizing Tif's to smaller gifs adds pixels

      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...@ Acm.Orgwrote:
      smullen.ucl...@ 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.t if"
      im = Image.open("tmp/tmsho20080901.t if")
      w, h = im.size
      im.thumbnail((6 00, 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("tm sho20080901.gif ")
      >
      ...
      >
      Using ImageMagick's convert I would do this...
      >
      convert -colors 256 -resize 600 -colorspace RGB -black-threshold 100 -
      contrast -intent Perceptual tmp/tmsho20080901.t if tmsho20080901.g if
      >
      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.t if")
           w, h = im.size
           im.thumbnail((6 00, h * 600 // w),
                        Image.ANTIALIAS ).save("tmp/sho20080901.png ")
      >
      --Scott David Daniels
      Scott.Dani...@A cm.Org

      Comment

      Working...