-
Notifications
You must be signed in to change notification settings - Fork 130
Description
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:
Warning: imageavif(): avif error - avif doesn't support palette images in /var/www/html/wp-includes/class-wp-image-editor.php on line 585
WebP conversion warning:
Warning: imagewebp(): Palette image not supported by webp in /var/www/html/wp-includes/class-wp-image-editor.php on line 585
Based on inspection of the PHP GD source:
Both imageavif()
and imagewebp()
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 in WP_Image_Editor_GD
always converts the source image to truecolor before any further processing hence, sub-sizes convert without issue.
References:
Steps to reproduce
- Force GD as the default image editor:
add_filter( 'wp_image_editors', function () {
return [ 'WP_Image_Editor_GD' ];
} );
- Ensure the Modern Image Formats plugin is installed and activated.
- Upload a palette-based PNG image (created or optimized by an online compressor like imageresizer.com).
Sample palette PNG image:
Sample transparent palette PNG image:
Screenshots
AVIF conversion warning:
Additional Context
- GD Version: bundled (2.1.0 compatible)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status