executeResize

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.

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

  1. \Contao\Image $image

    The 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
    {
        if () {
            // Do something and return the path to the resized image

            return $pathToResizedImage;
        }

        return null;
    }
}

References