Page MenuHomePhabricator

Python/Pillow image conversion result in broken image
Open, Stalled, Needs TriagePublicBUG REPORT


Steps to replicate the issue (include links if applicable):

  • in Python-code, image.convert('RGB').save(fp, "JPEG", quality=100)

What happens?:
Resulting image is corrupted/broken such as mostly white from grayscale image.

What should have happened instead?:
Image should look like the original image but be stored in different format.

Other information (browser name/version, screenshots, etc.):

Conversion problem appears at least when image type is "I" (32-bit signed integer pixels)
In Python-code, the type can be retrieved by image.getbands(). Normally this should return a tuple like "R, G, B" for a color image, but for certain images in TIFF-format it given "I". Trying to convert these images from TIFF to JPEG results in a broken image.

Event Timeline

Ipr1 changed the task status from Open to Stalled.Dec 7 2023, 4:50 AM
Ipr1 created this task.

List of types given by pillow documented here:

Code using pillow should check for certain types and avoid trying to convert those images at all, or find a different method to do so such as using another external library instead.

Example case: for file File:Vilho Penttilä, Kansallis-Osake-Pankin talo, Kauppakatu 4, Tampere.jpg, get TIFF-image from for musketti.M012:HK19700502:98.

TIFF-image shows correctly in programs like Darktable and RawTherapee so image itself is fine.

Some images with "L" band are converted fine while others are not. So that isn't a reliable method of checking either.