Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix saving of non-RGB thumbnails as PNG #17736

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

mweinelt
Copy link
Contributor

@mweinelt mweinelt commented Sep 20, 2024

The PNG format does not support non-RGB color spaces, which makes pillow raise an exception when trying to save e.g. a CMYK image in PNG format.

Converting to RGB is recommended on the upstream issue, and as CMYK is a print format transparency does not need to be considered.

Closes: #10741

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct
    (run the linters)

@CLAassistant
Copy link

CLAassistant commented Sep 20, 2024

CLA assistant check
All committers have signed the CLA.

The PNG format does not support non-RGB color spaces, which makes pillow
raise an exception when trying to save e.g. a CMYK image in PNG format.

Converting to RGB is recommended on the upstream issue, and as CMYK is a
print format transparency does not need to be considered.

Closes: element-hq#10741
@mweinelt mweinelt marked this pull request as ready for review September 20, 2024 11:33
@mweinelt mweinelt requested a review from a team as a code owner September 20, 2024 11:33
anoadragon453 added a commit that referenced this pull request Oct 3, 2024
@anoadragon453
Copy link
Member

anoadragon453 commented Oct 4, 2024

Thanks for the fix @mweinelt. I've attempted to write a test for this in #17786, but aren't actually seeing the test fail on develop, meaning I can't reproduce the issue... I've also tried just manually uploading the image from #10741 to matrix.org and thumbnail requests work fine.

Are you seeing this issue on your personal deployment? If so, what Pillow version are you using, and do you have a test image I could try?

@anoadragon453 anoadragon453 removed the request for review from a team October 4, 2024 08:50
@clokep
Copy link
Contributor

clokep commented Oct 4, 2024

I was writing some for to fix something similar and I suspect it only fails under dynamic thumbnails or something like that? Ie by default jpeg gets thumbailed as jpeg? There might be other configuration aspects too.

Copy link
Member

@anoadragon453 anoadragon453 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite not being able to reproduce this, the change doesn't appear to have any downsides as indeed CMYK does not have an alpha channel. I'd say we just merge it and see if this breaks anyone's workflow.

@anoadragon453 anoadragon453 merged commit 60aebdb into element-hq:develop Oct 8, 2024
39 checks passed
anoadragon453 added a commit that referenced this pull request Oct 8, 2024
@mweinelt mweinelt deleted the png-cmyk-thumbs branch October 9, 2024 20:12
@mweinelt
Copy link
Contributor Author

mweinelt commented Oct 9, 2024

I do not have a test image. Multiple times per day I spotted the same traceback as the author of the issue. I am not sure what images have been causing this.

Yes, private deployment on NixOS 24.05 with pillow 10.3.0.

@anoadragon453
Copy link
Member

Thanks for confirming the details! Please open a new issue if you see the problem reoccur after this change.

It should go out in Synapse v1.118.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Thumbnailing CMYK colorspace image gives Internal Server Error
4 participants