From 14c15845fa17979148137cf94dffb896e82370e0 Mon Sep 17 00:00:00 2001 From: Florian ALEXANDRE Date: Tue, 2 Apr 2024 17:25:16 +0200 Subject: [PATCH] fixe: issue with webp variation not taking the focuspoint into account --- src/lib/Imagine/FocusedImageAliasGenerator.php | 16 ++++++++++++++-- src/lib/Imagine/ImageAliasGenerator.php | 5 ++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/lib/Imagine/FocusedImageAliasGenerator.php b/src/lib/Imagine/FocusedImageAliasGenerator.php index 896ade3..dbdc90e 100644 --- a/src/lib/Imagine/FocusedImageAliasGenerator.php +++ b/src/lib/Imagine/FocusedImageAliasGenerator.php @@ -95,6 +95,19 @@ protected function getFocusPoint(\Ibexa\Core\FieldType\Value $fieldValue, string return null; } + protected function isFocusedThumbnail(string $variationName): bool + { + $variationConfig = $this->filterConfiguration->get($variationName); + if (isset($variationConfig['filters']['focusedThumbnail'])) { + return true; + } + if ($variationConfig['reference']) { + return $this->isFocusedThumbnail($variationConfig['reference']); + } + + return false; + } + /** * {@inheritdoc} * @@ -114,8 +127,7 @@ public function getVariation(Field $field, VersionInfo $versionInfo, $variationN $focusPoint = $this->getFocusPoint($field->value, $variationName); if (IORepositoryResolver::VARIATION_ORIGINAL !== $variationName) { - $variationConfig = $this->filterConfiguration->get($variationName); - if (isset($variationConfig['filters']['focusedThumbnail'])) { + if ($this->isFocusedThumbnail($variationName)) { $parameters = [ 'filters' => [ 'focusedThumbnail' => [ diff --git a/src/lib/Imagine/ImageAliasGenerator.php b/src/lib/Imagine/ImageAliasGenerator.php index 8e3359b..fb9a18b 100644 --- a/src/lib/Imagine/ImageAliasGenerator.php +++ b/src/lib/Imagine/ImageAliasGenerator.php @@ -175,10 +175,13 @@ private function applyFilter(BinaryInterface $image, string $variationName, arra isset($filterConfig['reference']) && IORepositoryResolver::VARIATION_ORIGINAL !== $filterConfig['reference'] ) { - unset($runtimeFiltersConfig['filters']); $image = $this->applyFilter($image, $filterConfig['reference'], $runtimeFiltersConfig); } + if (!isset($filterConfig['filters']['focusedThumbnail'])) { + unset($runtimeFiltersConfig['filters']['focusedThumbnail']); + } + return $this->filterManager->applyFilter($image, $variationName, $runtimeFiltersConfig); }