Original Full-Size AVIF/WEBP Conversion Fails on Palette-Based PNGs When GD is Used #2018
Labels
[Plugin] Modern Image Formats
Issues for the Modern Image Formats plugin (formerly WebP Uploads)
[Type] Bug
An existing feature is broken
Uh oh!
There was an error while loading. Please reload this page.
Bug Description
When uploading a PNG that was compressed using https://imageresizer.com/image-compressor, I encountered following PHP warnings during AVIF and WebP conversion.
AVIF conversion warning:
WebP conversion warning:
Based on inspection of the PHP GD source:
gdImageAvifCtx()
(imageavif) sourcegdImageWebp()
(imagewebp) sourceBoth
imageavif()
andimagewebp()
functions fail when passed a palette-based image, because GD requires truecolor images for these conversions.It appears these compression tools convert standard PNGs into palette-based (indexed color) PNGs. Due to this when uploading a palette-based (indexed color) PNG to WordPress media library, the original full-size AVIF/WebP file fails to convert and ends up as a 0-byte file.
However, resized sub-sizes are unaffected. Upon reviewing the GD editor code in WordPress core, I noticed that the
_resize()
method inWP_Image_Editor_GD
always converts the source image to truecolor before any further processing hence, sub-sizes convert without issue.References:
Steps to reproduce
Sample palette PNG image:


Sample transparent palette PNG image:
Screenshots
AVIF conversion warning:
WebP conversion warning:

Additional Context
The text was updated successfully, but these errors were encountered: