[Image-SIG] SystemError: tile cannot extend outside image

Christian Heimes christian at cheimes.de
Sun Mar 20 02:42:14 CET 2005


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.gif
Type: image/gif
Size: 905 bytes
Desc: not available
Url : http://mail.python.org/pipermail/image-sig/attachments/20050320/0a70a804/test.gif


More information about the Image-SIG mailing list