Make WordPress Core

Opened 12 months ago

Last modified 5 months ago

#59339 new defect (bug)

Conversion to webp causes fatal error when original image is a palette image (as opposed to truecolor)

Reported by: jakeparis's profile jakeparis Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.3.1
Component: Media Keywords:
Focuses: administration Cc:

Description

I am working on an image conversion plugin. I've run into a bug when the original image is a "paletter image"https://www.thecoderscamp.com/paletter-image-not-supported-by-webp/", or in other words, an image that has an indexed palette rather than being truecolor. I believe it's a png.

The error I get is:

Fatal error: Paletter image not supported by webp in /home/username/public_html/wp-includes/class-wp-image-editor.php on line 584

And how I'm using it:

<?php
$image_editor = wp_get_image_editor( $this->image_path );
$new_file_info = $this->get_editor()->save( $this->image_path, 'image/webp' );

This method worked fine on hundreds of images of png, jpg, and tiff until I ran into this one that has a "palette".

In wp-includes/class-wp-image-editor-gd.php:487, if the image loaded into WP_Image_Editor is a png, we check for a palette and convert to true color before saving. I believe that we need to also check in the webp conditional and, just like for png, convert to truecolor first.

Change History (2)

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


5 months ago

#2 @adamsilverstein
5 months ago

Hi @jakeparis - thanks for the bug report.

Can you please attach the image that causes the error? Also, can you check Tools->site Health -> Info -> Media to see if your system is using Imagick or GD (and the version).

Note: See TracTickets for help on using tickets.