Skip to content

Original Full-Size AVIF/WEBP Conversion Fails on Palette-Based PNGs When GD is Used #2018

@b1ink0

Description

@b1ink0

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

  1. Force GD as the default image editor:
add_filter( 'wp_image_editors', function () {
  return [ 'WP_Image_Editor_GD' ];
} );
  1. Ensure the Modern Image Formats plugin is installed and activated.
  2. Upload a palette-based PNG image (created or optimized by an online compressor like imageresizer.com).

Sample palette PNG image:
Image
Sample transparent palette PNG image:
Image

Screenshots

AVIF conversion warning:

Image

WebP conversion warning:
Image

Additional Context

  • GD Version: bundled (2.1.0 compatible)

Metadata

Metadata

Assignees

Labels

[Plugin] Modern Image FormatsIssues for the Modern Image Formats plugin (formerly WebP Uploads)[Type] BugAn existing feature is broken

Type

Projects

Status

Not Started/Backlog 📆

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions