Our local environments don't support WebP generation, but our staging and live environments do.
How do you take on this challenge?

Can there be some kind of fallback implemented?

Proposed solution:
Add a function that checks if the webp file exists + return false if not.

If return value is false: don't add the image in the responsive images.

A colleague is trying to implement this right now & will post the code over here if it succeeds.
Thanks.

CommentFileSizeAuthor
#5 webp-support_fallback-3121998-5.patch859 bytesgrimreaper

Comments

pietermouton created an issue. See original summary.

yorder.be’s picture

For the GD-toolkit, I have the following suggestion:

function webp_preprocess_responsive_image(&$variables) {
$gd_info = gd_info();

if (!$gd_info['WebP Support']) {
return false;
}

This way we prevent broken images on servers that don't support webp.

alexmoreno’s picture

feel free to submit a patch @yoram.derumeaux

grimreaper’s picture

Assigned: Unassigned » grimreaper
grimreaper’s picture

Assigned: grimreaper » Unassigned
Status: Active » Needs review
StatusFileSize
new859 bytes

Here is the patch.

Thanks for the review.

alexmoreno’s picture

Hi,

thanks a lot for your contribution.

I'm not convinced about this. If GD does not support webp, then it should be flagged on install, and maybe even block said install. Otherwise this could confuse the user as he would be expecting to see a webp image, but instead there would be none?

This is probably related as well:

https://www.drupal.org/project/webp/issues/3126853

Thanks again

alexmoreno’s picture

Status: Needs review » Needs work
alexmoreno’s picture

Status: Needs work » Postponed (maintainer needs more info)
pietermouton’s picture

Hi Alex,

Maybe not: in our case, we have the issue in switching between local/live environments.
Local, we don't use webp. Live, we do use it.

Maybe is adding it as config option (or setting a variable in settings.php) the best option to get around this.

joshua1234511’s picture

In settings file the following config can be used.

$config['toolkit'] = 'gd';

alexmoreno’s picture

IMHO, not having configured this in all environments would lead to problems to replicate and missing bugs. I like #10 for a more custom approach if needed

andypost’s picture

Status: Postponed (maintainer needs more info) » Active

As core added support for webp it could be handy to keep support of php-imagick as fallback option yo GD option