executeResize
Details
This page shows version 4.x. The current version can be found here.
The executeResize hook is triggered on whenever Contao resizes an image. It
passes the image object as an argument and expects either null or a the path
to the resized image as the return value. If the return value is null, other
hooks of the same type will still be executed.
Note
Using the executeResize and getImage hooks has been deprecated and will no
longer work in Contao 5.0. Use the contao.image.resizer service instead.
Parameters
\Contao\Image
$imageThe legacy image object instance.
Return Values
The path to the process image or null to keep the default behaviour.
Example
// src/EventListener/ExecuteResizeListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\Image;
#[AsHook('executeResize')]
class ExecuteResizeListener
{
public function __invoke(Image $image): string|null
{
if (…) {
// Do something and return the path to the resized image
return $pathToResizedImage;
}
return null;
}
}