This module is not compatible with Image Widget Crop.

It could be a great feature.

Comments

Asterovim created an issue. See original summary.

psebborn’s picture

When you say "it doesn't work" what do you mean?

I had an issue where the WebP image wouldn't get flushed if the image style was flushed (for example when you update the crop).
I worked around it by adding a `hook_image_style_flush` hook and manually removing the file, e.g.

/**
 * Implements hook_image_style_flush().
 * 
 * The WebP image style doesn't get flushed properly when the ImageWidgetCrop
 * module is used. Force delete them when the normal image style gets removed.
 *
 * @see \Drupal\image\ImageStyleInterface::flush
 */
function MYMODULE_image_style_flush($style, $path) {
  /** @var \Drupal\Core\File\FileSystemInterface $file_system */
  $file_system = \Drupal::service('file_system');
  if (isset($path)) {
    $derivative_uri = $style->buildUri($path);
    /* @var \Drupal\webp\Webp $webp */
    $webp = \Drupal::service('webp.webp');
    $webp_url = 'public://styles' . $webp->getWebpFilename($derivative_uri);
    if (file_exists($webp_url)) {
      try {
        $file_system->delete($webp_url);
      }
      catch (FileException $e) {
        // Ignore failed deletes.
      }
    }
  }
}

I also needed a patch from https://www.drupal.org/project/drupal/issues/2833129 as the hooks wasn't getting fired.
Hope this helps you out!

alexmoreno’s picture

Status: Active » Postponed (maintainer needs more info)
alexmoreno’s picture

Priority: Major » Normal
nginex’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)
Related issues: +#3153137: Using Image Widget Crop in responsive images does not refresh webp image

Closing this issue as duplication of #3153137: Using Image Widget Crop in responsive images does not refresh webp image. I created that issue against dev version of the module and provided more details

arakwar’s picture

Reading both issues, I do think that going trough the hook is closer to what developers would expect modules to do, but since it relies on a core patch in 9.x, maybe going trough nginex solution makes sense... we're going to test it on our side.