[Image-SIG] Re: Re: PIL Bug: Crash processing GIF image

Fredrik Lundh fredrik at pythonware.com
Sat Feb 21 04:38:20 EST 2004


Chris Cogdon wrote:
>
> > it looks like the GIF codec messes up when it's trying to determine
> > the right size of the file, which results in a 62004-pixel high image
> > memory, which results in a 0-pixel wide thumbnail, which causes the
> > quantization code to mess up.
>
> Wow... that's weird :) I agree that both PIL and ImageMagick report the
> 62004 pixel high image... it certainly doesn't LOOK that way when
> viewed in a browser :)

the GIF format uses both a "logical screen size" and a bounding box
for the actual pixel data.  in this file, the screen size is (53, 62004)
while the bounding box is (0, 0, 444, 599).

when PIL reads this image, it creates an image memory large enough
to hold the entire screen, and then pastes the pixels into the given
bounding box.  ImageMagick probably does the same thing, while the
browser you're using only grabs the pixel data.

if you want to ignore the logical screen, you can manipulate the "size"
and "tile" attributes after you've opened the file, but before you've done
anything else with the image:

i = Image.open(...)

if i.tile[0][0] == "gif":
    # only read the first "local image" from this GIF file
    x0, y0, x1, y1 = i.tile[0][1]
    i.size = x1-x0, y1-y0
    del i.tile[1:]

(you can place this code inside the aspect ratio check in my earlier
example)

</F>






More information about the Image-SIG mailing list