Skip to content
Snippets Groups Projects

Issue #3195113: Webp images are not working with s3fs

1 file
+ 7
0
Compare changes
  • Side-by-side
  • Inline
@@ -31,6 +31,7 @@ function imageapi_optimize_webp_responsive_preprocess_responsive_image(&$variabl
$image_styles = ImageStyle::loadMultiple($entity->getImageStyleIds());
$pipeline_webp_map = [];
$image_style_map = [];
$tokens_webp = [];
// Iterate through the ImageStyles and look for the WebP processor.
foreach ($image_styles as $image_style) {
// If ImageStyle has pipeline, build map if WebP processor exists.
@@ -56,6 +57,8 @@ function imageapi_optimize_webp_responsive_preprocess_responsive_image(&$variabl
$webp_relative_path = str_replace($image_relative_path_file,
$image_relative_path_file . '.webp', $image_relative_path);
$image_style_map[$image_relative_path] = $webp_relative_path;
$tokens_webp[$image_style->getPathToken($variables['uri'])] =
$image_style->getPathToken($variables['uri'] . '.webp');
}
}
}
@@ -74,6 +77,10 @@ function imageapi_optimize_webp_responsive_preprocess_responsive_image(&$variabl
if ($offset_key) {
$source_srcset = $source->offsetGet($offset_key)->value();
$cloned_srcset = strtr($source_srcset, $image_style_map);
// Replace old tokens with valid.
$cloned_srcset = str_replace(array_keys($tokens_webp), $tokens_webp, $cloned_srcset);
if($source_srcset != $cloned_srcset) {
$source_webp = clone $source;
$source_webp->offsetSet($offset_key, $cloned_srcset);
Loading