Skip to content

'None or too many quantization tables' ValueError on some images #4825

@radio-van

Description

@radio-van

What did you do?

from io import BytesIO
from PIL import Image

image = Image.open(fp)

buf = BytesIO()
image.save(buf, format='JPEG', quality='keep', optimize=True)

What did you expect to happen?

Successful image saving.

What actually happened?

  File ".../python2.7/site-packages/PIL/Image.py", line 2084, in save
    save_handler(self, fp, filename)
  File "../python2.7/site-packages/PIL/JpegImagePlugin.py", line 699, in _save
    qtables = validate_qtables(qtables)
  File "../python2.7/site-packages/PIL/JpegImagePlugin.py", line 683, in validate_qtables
    raise ValueError("None or too many quantization tables")
ValueError: None or too many quantization tables

What are your OS, Python and Pillow versions?

  • OS: ArchLinux 5.7.10-arch1-1 x86_64 GNU/Linux
  • Python: 2.7.17, 3.8.2
  • Pillow: 6.2.2, 7.1.2

Bug can be reproduced only with some images (see attached one), I'm not sure what's "wrong" with this image, it has progressive encoding and seems to lack a color profile, but most tools (ffmpeg, ImageMagic) work with it without any issues.

Bug can be reproduced on both Python 2 (Pillow 6.2.2) and Python 3 (Pillow 7.1.2).
My workaround is to set quality=100 instead of quality='keep'.

example.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions