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.
}
}
}
}
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.
Comments
Comment #2
psebborn commentedWhen 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.
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!
Comment #3
alexmoreno commentedComment #4
alexmoreno commentedComment #5
nginex commentedClosing 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
Comment #6
arakwarReading 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.