WordPress / wordpress-playground

Run WordPress in the browser via WebAssembly PHP
https://w.org/playground/
GNU General Public License v2.0
1.64k stars 257 forks source link

PHP: Support libwebp on PHP 7.0 – 7.3 #1381

Closed sejas closed 2 weeks ago

sejas commented 6 months ago

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

https://github.com/WordPress/wordpress-playground/assets/779993/e8e3f6d3-e54c-4fcf-8ed9-1a7f3b72681f

adamziel commented 6 months ago

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

sejas commented 6 months ago

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

brandonpayton commented 6 months ago

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 https://github.com/libgd/libgd/pull/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:

adamziel commented 5 months ago

We'd likely need to build GD with libwebp.

adamziel commented 5 months ago

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 5 months ago

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