Skip to content

[4.x] How to customise image transform creation? #11347

Answered by d--j
d--j asked this question in Q&A
Discussion options

You must be logged in to vote

As @brandonkelly suggested, I took the route to hook into Asset::EVENT_BEFORE_GENERATE_TRANSFORM until using a custom ImageTransformer is feasible.

For anyone stumbling onto this wanting to do the same: here is how this approximately looks like:

Event::on(
    Asset::class,
    Asset::EVENT_BEFORE_GENERATE_TRANSFORM,
    function (GenerateTransformEvent $event) {
        if ($event->transform && preg_match('~^authorSquare(\d+)$~', $event->transform->handle ?? '')) {
            $event->url = $this->getAuthorSquareAssetUrl($event->asset, $event->transform);
        }
    }
);


public function getAuthorSquareAssetUrl(Asset $asset, ImageTransform $transform): ?string
{
    $match = [];
    if

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@d--j
Comment options

@brandonkelly
Comment options

Comment options

You must be logged in to vote
1 reply
@timkelty
Comment options

Answer selected by d--j
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants