[tl] WebP Image Integration [Deleted]

truonglv

Well-known member
truonglv submitted a new resource:

[tl] WebP Image Integration - Optimize images with webp to improvement page load

Features​

  • Convert all attachment images (PNG, JPEG) to WebP format
  • Convert all user avatars to WebP

Pre-installation​

This is self-host service so it's does not work with shared hosting

Ubuntu:
Bash:
apt-get install webp

CentOS:
Bash:
yum install webp

Run this command to make sure it installed
Bash:
which cwebp

In case OK it should be display like /usr/bin/cwebp...

Read more about this resource...
 
I'm slightly confused as to why this requires the installation of various binaries when PHP GD natively supports webp as it is?

This is the minimum amount of code required to convert a 1.5MB jpg to a 300KB webp:
PHP:
$image = imagecreatefromjpeg('/path/to/sample.jpg');
imagewebp($image, '/path/to/sample.webp');
 
I'm slightly confused as to why this requires the installation of various binaries when PHP GD natively supports webp as it is?

This is the minimum amount of code required to convert a 1.5MB jpg to a 300KB webp:
PHP:
$image = imagecreatefromjpeg('/path/to/sample.jpg');
imagewebp($image, '/path/to/sample.webp');
That right but webp provide more options especially lossless while converting images.
 
Does this addon serve webp images to browsers that support it and original format to those that don't?
 
No. It’s replacement.
Some ~5% of browsers still don't support webp, so simply replacing all images with webp variants is not a good idea...

The webp replacement should only be done when the browser sends that it accepts it in the request, something like the following should work:
PHP:
if( strpos( $_SERVER['HTTP_ACCEPT'], 'image/webp' ) !== false ) {
    // enable_webp_serving();
}
 
Some ~5% of browsers still don't support webp, so simply replacing all images with webp variants is not a good idea...

The webp replacement should only be done when the browser sends that it accepts it in the request, something like the following should work:
PHP:
if( strpos( $_SERVER['HTTP_ACCEPT'], 'image/webp' ) !== false ) {
    // enable_webp_serving();
}
It’s trade off. With webp and lossless you save a lot of storage.

In the case you want to support old browsers you may save 2 versions of image (webp and original) which intense your storage or decode while serving images which intensely cpu
 
Top Bottom