-
Notifications
You must be signed in to change notification settings - Fork 139
Fixes palette-based PNG uploads failing original full-size AVIF/WebP conversion under GD #2024
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
Fixes palette-based PNG uploads failing original full-size AVIF/WebP conversion under GD #2024
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #2024 +/- ##
==========================================
+ Coverage 68.54% 68.61% +0.06%
==========================================
Files 91 91
Lines 7930 7956 +26
==========================================
+ Hits 5436 5459 +23
- Misses 2494 2497 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @IlyaZha, @mytory, @chimok. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
felixarntz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@b1ink0 Thank you, this looks great to me so far, just one comment.
It would be great to get @adamsilverstein's review on this as well.
Co-authored-by: Weston Ruter <[email protected]>
|
Hi @b1ink0 and thanks for the PR.
Good catch! I understand the technical requirement for GD here and agree we need to address them to resolve this issue. My only concern is that by converting a palette image (up to 8 bit) to truecolor (eg. 24 bit), we might inadvertently bloat the image size. We tried to address this for Imagick in https://core.trac.wordpress.org/ticket/36477. I'd love to see some before/after size numbers for indexed PNG uploads converted to WebP and AVIF to confirm that isn't the case. I suspect we are ok given the lossy compression of WebP/AVIF vs the lossless PNG compression, but it would be worth checking and perhaps adding a unit test for this aspect. |
Co-authored-by: Adam Silverstein <[email protected]>
|
I was able to verify the issue with the Bedrock container and some code to force using GD. I also verified the PR fixes the issue. This should be good to go. We should probably port this fix to WordPress core since this will also affect anyone using the core output filter directly with the same configuration. |
|
@b1ink0 - this looks very close, thanks! I left a few additional comments, let me know what you think. |
Co-authored-by: Adam Silverstein <[email protected]>
adamsilverstein
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, nice work!
|
I opened a ticket to move this fix upstream to core since I expect it is a bug there: https://core.trac.wordpress.org/ticket/63773#ticket |
|
@b1ink0 if you have a moment, can you please review my fix and test for core: WordPress/wordpress-develop#9368. The tests would benefit from being expanded to be more through, I wanted to capture the simplest case first to validate the test fails before and is fixed after the change. |
|
@adamsilverstein Yes, the patch looks good and is working all tests pass with your patch. When the logic for I think also adding a test to ensure the size of the converted WebP from truecolor is smaller than the palette PNG would be good, as you suggested in this PR. Also tested Modern Image Formats version 2.5.1 installed through the WordPress plugin directory with the core patched there is no error when uploading a palette-based PNG. |
westonruter
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple tiny suggestions.
|
Here's a build of the plugin in this branch's current state: webp-uploads.zip |
|
Fix confirmed: #1576 (comment) |
Co-authored-by: Weston Ruter <[email protected]>
… fix/palette-pngs-to-avif-webp-conversion
Summary
Fixes #2018, #1561, #1864
Relevant technical choices
This change hooks into both
wp_handle_upload_prefilterandwp_handle_sideload_prefilterto detect palette-based (indexed-color) PNGs and convert them in-place to truecolor while preserving transparency before any AVIF/WebP encoding takes place. It preserves all existing upload metadata and only affects PNGs handled by the GD image editor.