Repository navigation
FIX: Handle CMYK images when output format is PNG in image converters (#3257) - #3258
Merged
Roman Lutz (romanlutz) merged 4 commits intoOct 17, 2026
Merged
Conversation
Contributor
Author
|
Normalizes CMYK images to RGB before saving to PNG in Ready for review! |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f1bae157-7a50-4003-9e2a-977b72f628d2
Preserve the existing RGB conversion while removing its stale CMYK profile. Cover profile removal, source metadata preservation, saved output, and valid RGB/RGBA profile preservation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f1bae157-7a50-4003-9e2a-977b72f628d2
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f1bae157-7a50-4003-9e2a-977b72f628d2
Roman Lutz (romanlutz)
approved these changes
Oct 17, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 17, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 17, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to no response for status checks
Oct 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3257
Description
BaseImageToImageConverter(which powersImageResizingConverter) andImageCompressionConvertersupport converting and compressing images across JPEG, PNG, and WEBP formats.However, when processing an image in
CMYKcolor mode (common in print media, scans, and press JPEGs) withoutput_format="PNG", Pillow's PNG encoder (PIL.PngImagePlugin) throws an uncaughtKeyError: 'CMYK'wrapped inOSError: cannot write mode CMYK as PNGbecause PNG does not support CMYK.BaseImageToImageConverter._transform_image: format preparation was only performed foroutput_format == "JPEG". Whenoutput_format == "PNG", CMYK images were passed directly totransformed.save(buffer, "PNG").ImageCompressionConverter._compress_image: format preparation was also only performed foroutput_format == "JPEG". PNG targets with CMYK mode bypassed mode normalization and crashed uponimage.save(compressed_bytes, output_format, **save_kwargs).This change normalizes CMYK images to RGB before saving to PNG:
BaseImageToImageConverter._transform_image: converts CMYK images using the existingself._convert_to_rgb_or_rgba(image)helper whenoutput_format == "PNG".ImageCompressionConverter._compress_image: converts CMYK images to RGB viaimage.convert("RGB")whenoutput_format == "PNG".L,LA,1), paletted (P), and transparent (RGBA) PNGs remain completely untouched.Tests and Documentation
tests/unit/converter/test_image_resizing_converter.py:test_image_resizing_converter_cmyk_to_png_conversionverifies CMYK to PNG conversion, resulting formatPNG, modeRGB, and expected resized dimensions.tests/unit/converter/test_image_compression_converter.py:test_image_compression_converter_cmyk_to_png_conversionverifies CMYK compression to PNG without raisingOSError, yielding formatPNGand modeRGB.uv run python -m pytest tests/unit/converter/test_image_resizing_converter.py tests/unit/converter/test_image_compression_converter.py: 42 passed in 6.40sruff checkandruff format --checkclean.