I've an issue with GIF and maybe other images with extrem ratio. The attached gif file has a ration of 300x15 pixels and file resizing.

exception:
...
Module PIL.Image, line 1136, in save
Module PIL.PngImagePlugin, line 510, in _save
Module PIL.ImageFile, line 474, in _save
SystemError: tile cannot extend outside image

PIL version:
   1.1.4 and 1.1.5rc1 with python 2.3.5

target size:
  16 x 16

method:
    def scale(self, data, w, h):
        """ scale image (with material from ImageTag_Hotfix)"""
        # make sure we have valid int's
        size = int(w), int(h)

        pilfilter = PIL.Image.NEAREST
        # check for the pil version and enable antialias if > 1.1.3
        if PIL.Image.VERSION >= "1.1.3":
            pilfilter = PIL.Image.ANTIALIAS

        original_file=StringIO(data)
        image = PIL.Image.open(original_file)
        # consider image mode when scaling
        # source images can be mode '1','L,','P','RGB(A)'
        # convert to greyscale or RGBA before scaling
        # preserve palletted mode (but not pallette)
        # for palletted-only image formats, e.g. GIF
        # PNG compression is OK for RGBA thumbnails
        original_mode = image.mode
        if original_mode == '1':
            image = image.convert('L')
        elif original_mode == 'P':
            image = image.convert('RGBA')
        image.thumbnail(size, pilfilter)
        format = image.format and image.format or 'PNG'
        # decided to only preserve palletted mode
        # for GIF, could also use image.format in ('GIF','PNG')
        if original_mode == 'P' and format == 'GIF':
            image = image.convert('P')
        thumbnail_file = StringIO()
        # quality parameter doesn't affect lossless formats
        image.save(thumbnail_file, format, quality=88)
        thumbnail_file.seek(0)
        return thumbnail_file, format.lower()

Christian

<<inline: test.gif>>

_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig

Reply via email to