diff --git a/code_samples/back_office/images/src/Event/RemovePngquantOptimizer.php b/code_samples/back_office/images/src/Event/RemovePngquantOptimizer.php new file mode 100644 index 0000000000..91d30ab9a7 --- /dev/null +++ b/code_samples/back_office/images/src/Event/RemovePngquantOptimizer.php @@ -0,0 +1,22 @@ + 'onConfigureOptimizers', + ]; + } + + public function onConfigureOptimizers(ConfigureImageOptimizersEvent $event): void + { + $event->removeOptimizer(Pngquant::class); + } +} diff --git a/composer.json b/composer.json index 690d297d96..2467d6a85f 100644 --- a/composer.json +++ b/composer.json @@ -76,7 +76,8 @@ "ibexa/collaboration": "~4.6.x-dev", "ibexa/share": "~4.6.x-dev", "ibexa/phpstan": "~4.6.-dev", - "ibexa/cdp": "~4.6.x-dev" + "ibexa/cdp": "~4.6.x-dev", + "ibexa/image-editor": "~4.6.x-dev" }, "scripts": { "fix-cs": "php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots", diff --git a/docs/api/event_reference/other_events.md b/docs/api/event_reference/other_events.md index 569e71a117..7216c52f7a 100644 --- a/docs/api/event_reference/other_events.md +++ b/docs/api/event_reference/other_events.md @@ -60,6 +60,17 @@ The following events are dispatched when changing the user settings available in |---|---|---| |`PublishVersionEvent`|`PublishAssetEventDispatcher::emitPublishAssetEvent`|`Content $content`
`Connector\Dam\AssetIdentifier $assetIdentifier`
`Connector\Dam\AssetSource $assetSource`| +## Image Editor + +The following event is dispatched when the Image Editor optimizes an image. +You can subscribe to it to customize the list of active image optimizers at runtime. + +For more information, see [Customizing image optimizers with an event](images.md#customizing-image-optimizers). + +| Event | Dispatched by | Properties | +|---|---|---| +|[`ConfigureImageOptimizersEvent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ImageEditor-Event-ConfigureImageOptimizersEvent.html)|`SpatieChainOptimizer::`
`optimize`|`array $optimizers`| + ## Form Builder [[% include 'snippets/experience_badge.md' %]] [[% include 'snippets/commerce_badge.md' %]] | Event | Dispatched by | Properties | diff --git a/docs/content_management/images/images.md b/docs/content_management/images/images.md index 2d4a6577bf..dea435e0df 100644 --- a/docs/content_management/images/images.md +++ b/docs/content_management/images/images.md @@ -254,6 +254,17 @@ Install these libraries using your package manager, for example: sudo apt-get install optipng ``` +### Customizing image optimizers + +When the Image Editor saves a modified image, the system dispatches the [`ConfigureImageOptimizersEvent`](other_events.md#image-editor) event before running the optimizer chain. +You can listen to this event to customize the list of image optimizers at runtime. + +The following example shows how to remove the Pngquant optimizer to prevent grayscale conversion of low-saturation PNG images: + +``` php +[[= include_file('code_samples/back_office/images/src/Event/RemovePngquantOptimizer.php') =]] +``` + ## Embedding images in Rich Text The [RichText](richtextfield.md) field allows you to embed other content items within the field.