Score:3

How can I use core's WebP support instead of the WebP module?

cn flag

According to the change record, Drupal 9.2 supports WebP for better image compression.

I've been using the WebP module on my 9.1 site to serve WebP images, but it has a performance-killing bug and I would like to use Core if possible.

So when I upgrade to 9.2, how can I replace the WebP module with core's WebP support?

I upgraded to 9.2, uninstalled WebP, and searched for WebP options, but couldn't find anything.

This Lullabot post said it should be supported in the Convert effect, but I don't see the option.

Score:6
cn flag

WebP is supported in the GD image toolkit.

As noted in the change record, you can check whether your version of PHP has WebP support by going to admin/reports/status/php#module_gd.

What if I am using Imagemagick?

If you do a lot of image processing on your site, you may be using the ImageMagick toolkit via the ImageMagick contrib module. In this case, it doesn't matter if the GD support is enabled because Drupal is using Imagemagick, not GD.

So first, check your image toolkit at /admin/config/media/image-toolkit. If you are using ImageMagick, you need to do the following:

  1. Click Image formats accordion title on /admin/config/media/image-toolkit.
  2. In Enable/disable image formats, scroll down to WEBP and set enabled: true.
  3. Save.

This will now let you convert to WebP for your image styles. (/admin/config/media/image-styles)

What if I am using responsive images?

If you are using responsive image styles on your site via the core Responsive Image module, and you convert all your image styles to WebP, you will break support for older versions of Safari and Internet Explorer, which do not support WebP. (caniuse webP)

This is something the WebP module handles automatically, but core does not. So if you convert everything to WebP and call it a day, you will break your site for some users.

Unfortunately, core's Responsive Image module only supports breakpoints based on viewport size, but the correct approach is to set the type on the tag, which core does not allow you to do. There is a drupal.org issue about this.

Workarounds:

  • Use the WebP or ImageOptimize WebP modules instead of core.
  • For each responsive image style (/admin/config/media/responsive-image-style/MY_STYLE), use image styles converted to WebP for all the breakpoints, and then use a non-WebP image style as the Fallback image style.
br flag
Note regarding the performance that there is a patch ready, and my aim would be to merge it in the next few days and get a stable release ASAP
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.