diff --git a/Classes/Aspects/ThumbnailAspect.php b/Classes/Aspects/ThumbnailAspect.php index f6caf4a..b39aba5 100644 --- a/Classes/Aspects/ThumbnailAspect.php +++ b/Classes/Aspects/ThumbnailAspect.php @@ -109,6 +109,15 @@ public function generateImgproxyUri(JoinPointInterface $joinPoint): ?array $expectedSize = ImgproxyBuilder::expectedSize($actualDimension, $targetDimension, $resizingType, $enlarge); + foreach ($this->settings['imgproxyUrlModifiers'] as $modifierClassName){ + if(class_exists($modifierClassName)){ + $modifier = new $modifierClassName(); + if(is_callable($modifier)){ + $modifier($url, $configuration); + } + } + } + return [ 'width' => $expectedSize->getWidth(), 'height' => $expectedSize->getHeight(), diff --git a/Classes/ImgproxyUrl.php b/Classes/ImgproxyUrl.php index 9401be2..a647010 100644 --- a/Classes/ImgproxyUrl.php +++ b/Classes/ImgproxyUrl.php @@ -76,4 +76,9 @@ public function cacheBuster(string $cacheBuster) { $this->processingOptions[] = 'cb:' . $cacheBuster; } + + public function addProcessingOption($key, $value) + { + $this->processingOptions[] = $key . ':' . $value; + } } diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index 60421e0..ca65301 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -16,6 +16,9 @@ Networkteam: # Let imgproxy choose the file extension based on client preferences autoFormat: true + # This allows to modify the imgproxy url before it gets returned + imgproxyUrlModifiers: [] + # Format Quality, eg: 'jpg:75:avif:80:webp:70' formatQuality: '' diff --git a/README.md b/README.md index b4b7171..43f8231 100644 --- a/README.md +++ b/README.md @@ -55,3 +55,25 @@ docker run -p 8080:8080 -it \ * Neos will **not generate any thumbnail**, they are generated ad-hoc from imgproxy as soon as a client requests it. Note: make sure to add a caching proxy / CDN on top of imgproxy, it has no built-in caching! + +## How to modify the imgproxy url +If you need to modify the imgproxy url for your custom needs you can use the following hook: +1. Create a modifier class in this format: +``` +namespace Foo\Bar; + +class ModifierClass +{ + public function __invoke(ImgproxyUrl $url, ThumbnailConfiguration $configuration): void + { + // modify the ImgproxyUrl object + } +} +``` +2. Register your modifier in the settings: +``` +Networkteam: + ImageProxy: + imgproxyUrlModifiers: + - Foo\Bar\ModifierClass +``` \ No newline at end of file