Issue #34 new

Import method of Image module changes Image.save() behavior

Stefan "hr" Berder
created an issue

Foreword

I'm fairly new to PIL and don't really now where to dig yet so I'll give as much information as I can to help solve the problem.

Issue

Trying to resize an image, I followed several resources on internet and imported Image directly:

import Image
img = Image.open('EipauJU.jpg')
newimg = img.resize((131, 180), Image.ANTIALIAS)
newimg.save('EipauJU-thumb.jpg')

When running I get the following exception.

Traceback (most recent call last):
  File "test_pil.py", line 4, in <module>
    newimg.save('EipauJU-thumb.jpg')
  File "/usr/lib/python2.6/dist-packages/PIL/Image.py", line 1439, in save
    save_handler(self, fp, filename)
  File "/usr/lib/python2.6/dist-packages/PIL/JpegImagePlugin.py", line 471, in _save
    ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)])
  File "/usr/lib/python2.6/dist-packages/PIL/ImageFile.py", line 494, in _save
    for e, b, o, a in tile:
ValueError: Not a valid numbers of quantization tables. Should be between 2 and 4.

The file is still created and is indeed the resized version of the original:

$ ls EipauJU*
EipauJU.jpg  EipauJU-thumb.jpg

If using Image.thumbnail(), the same exception happens:

import Image
img = Image.open('EipauJU.jpg')
img.thumbnail((131, 180), Image.ANTIALIAS)
img.save('EipauJU-thumb.jpg')

Solution

If I use from PIL import Image, the exception doesn't happen anymore.

Environment:

  • System: Debian 6.0.7 (squeeze)
  • Library version: installed using pillow in a virtualenv
$ pip freeze
[...]
PIL==1.1.7
Pillow==2.0.0
[...]
  • Dependency libraries:
ii  libjpeg62                            6b1-1                        The Independent JPEG Group's JPEG runtime library (version 6.2)
ii  libjpeg8                             8b-1                         The Independent JPEG Group's JPEG runtime library
ii  libjpeg8-dev                         8b-1                         Development files for the IJG JPEG library
ii  zlib1g                               1:1.2.3.4.dfsg-3             compression library - runtime
ii  zlib1g-dev                           1:1.2.3.4.dfsg-3             compression library - development
  • Shared libraries on _imaging.so:
$ ldd _imaging.so 
        linux-gate.so.1 =>  (0xf57fe000)
        libjpeg.so.8 => /usr/lib/libjpeg.so.8 (0xb766e000)
        libz.so.1 => /usr/lib/libz.so.1 (0xb765a000)
        libpthread.so.0 => /lib/i686/cmov/libpthread.so.0 (0xb7641000)
        libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb74f9000)
        /lib/ld-linux.so.2 (0xb76e9000)
{0: array('b', [5, 4, 4, 4, 4, 4, 5, 4, 4, 5, 7, 5, 4, 5, 7, 9, 7, 5, 5, 7, 9, 10, 8, 8, 9, 8, 8, 10, 13, 10, 11, 11, 11, 11, 10, 13, 12, 12, 12, 13, 12, 12, 12, 15, 15, 17, 17, 15, 15, 23, 22, 22, 22, 23, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25]), 1: array('b', [6, 6, 6, 10, 9, 10, 20, 13, 13, 20, 22, 17, 14, 17, 22, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25])}

Let me know if you need more information or tests.

Comments (2)

  1. Log in to comment