You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG: BaseImageToImageConverter and ImageCompressionConverter crash on CMYK images when output format is PNG #3257
BaseImageToImageConverter and ImageCompressionConverter support converting and compressing images across JPEG, PNG, and WEBP formats. However, when processing an image in CMYK color mode (common in print media, scans, and press JPEGs) with output_format="PNG", both converters crash with an unhandled OSError:
KeyError: 'CMYK'
OSError: cannot write mode CMYK as PNG
Root Cause
Pillow's PNG encoder (PIL.PngImagePlugin) only supports modes 1, L, LA, I, I;16, P, RGB, and RGBA. When saving a CMYK image to a PNG buffer, Pillow raises KeyError: 'CMYK'.
In BaseImageToImageConverter._transform_image:
Mode conversion is only handled for output_format == "JPEG" via _prepare_image_for_jpeg. Although BaseImageToImageConverter already defines _convert_to_rgb_or_rgba(image), it is never called when output_format == "PNG". Subclasses such as ImageResizingConverter pass CMYK images directly to transformed.save(buffer, "PNG"), crashing at runtime.
In ImageCompressionConverter._compress_image:
Format preparation is likewise only performed for output_format == "JPEG". PNG targets with CMYK mode bypass mode normalization and crash upon image.save(compressed_bytes, output_format, **save_kwargs).
Activity
FIX: Handle CMYK images when output format is PNG in image converters (…