WordPress/wordpress-playground

PHP: Support libwebp on PHP 7.0 – 7.3

Closed this issue · 6 comments

sejas commented

Some Studio users reported an error uploading webp images to the Media Gallery.

Steps to reproduce:

  1. Download a webp image to your computer. For example: https://www.gstatic.com/webp/gallery/1.webp
  2. Access https://playground.wordpress.net/
  3. Navigate to Media > Upload Images
  4. Select the downloaded image
  5. Observe the error: This image cannot be processed by the web server. Convert it to JPEG or PNG before uploading.

Workaround

  1. Rename the image from 1.webp to 1.jpg in your computer.
  2. Try again uploading the image to the WordPress Media Library
  3. Observe the file is correctly uploaded and it has the webp extension

Screencast

webp-error-and-workaround.mp4

@sejas just to make sure – does this work in regular WordPress?

sejas commented

Yes! I tried it in a regular WordPress without plugins and it worked without any issues.

From the "Using WebP images" section of the WP WebP announcement post:

In WordPress, the lossless WebP format is only supported when the hosting server uses Imagick (the PHP library) until LibGD adds support.

It looks like libgd ought to support webp now based on libgd/libgd#698 merging.

But Playground doesn't appear to support webp. From the Playground WP-CLI demo:

$ wp eval 'var_dump(array_search( "gd", get_loaded_extensions() ) );'
int(13)

$ wp eval 'var_dump(wp_image_editor_supports( array( "mime_type" => "image/webp" ) ) );'
bool(false)

In Playground, PHP loads the "gd" extension, but WP doesn't think the image editor supports webp. Some possibilities:

  • Maybe WP doesn't yet support webp images via libgd.
  • Maybe our version of libgd is old enough to be missing webp support
  • Maybe our build of libgd doesn't include webp support

We'd likely need to build GD with libwebp.

This is now resolved for PHP >= 7.4, but not for 7.0 – 7.3. How important is webp support in these version for you @sejas?

sejas commented

Thank you for fixing the webp issue for PHP 7.4+. You are Awesome!

The main reason we don't need to support older versions is that PHP 7.4 and even 8.0 are already deprecated. Versions lower than 7.3 do not appear in the chart 😆.

https://www.php.net/supported-versions.php