Images styles should be converted to WebP

Created on 19 June 2024, 6 months ago
Updated 4 September 2024, 4 months ago

Problem/Motivation

Drupal core's image styles are now converted to webP. https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/image...

Is it possible for this module to create WebP images for each of the generated image styles?

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Active

Version

1.3

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @thejimbirch
  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    You'll be able to do this once ✨ Alter hook to adjust image effect RTBC lands, or you can start using the patch now:

    /**
     * Implements hook_easy_responsive_images_image_style_alter().
     */
    function my_module_easy_responsive_images_image_style_alter(ImageStyleInterface $entity): void {
      foreach ($entity->getEffects() as $effect) {
        if ($effect->getPluginId() === 'image_convert') {
          return;
        }
      }
    
      $entity->addImageEffect([
        'id' => 'image_convert',
        'data' => [
          'extension' => 'webp',
        ],
      ]);
    }
    
  • πŸ‡ΊπŸ‡ΈUnited States fathershawn New York

    Perhaps I'm missing something but a default pipeline using ImageAPI Optimize and a processor like ImageAPI Optimize AVIF WebP β†’ takes care of this.

  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    ImageAPI Optimize introduces an overhead and is very much overkill if all you want to do is convert images to Webp, because this is supported by core image styles.

  • πŸ‡§πŸ‡ͺBelgium kubrick

    The module used to convert to webp if you had eighter imageapi_optimize_webp or the webp module, but there's been a regression in the latest version when avif support was added.

    I agree #2 would be a more elegant solution since it does not require any extra modules.

    Not sure if I should open a new issue for this or we should just focus on getting ✨ Alter hook to adjust image effect RTBC to stable.

    For now I've added my fixes in a patch.
    It should serve avif, webp or fall back to the original format depending on which modules you have installed.

  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    You should probably open a new issue for that regression, because I’m not sure if ✨ Alter hook to adjust image effect RTBC is going anywhere soon.

  • πŸ‡³πŸ‡±Netherlands seanB Netherlands

    Merged ✨ Alter hook to adjust image effect RTBC ! I think the patch in #5 makes sense, but could you create a new issue for that with an MR? I'd be glad to merge that as well.

    Regarding this issue, I guess if we could drop special support for the avif, webp and imageapi_optimize_webp modules now image_convert is in core. At least that makes sense.

    Maybe we could create a setting in the module to select if we want to convert images to avif or webp automatically, and add the image_convert action to all generated image styles?

Production build 0.71.5 2024