How can I trigger an image transform in a Craft plugin?

1 Answer 1


Yes, it's possible.

It essentially works just like it does in twig...you just call getURL with the valid name of a transform

$criteria = craft()->elements->getCriteria(ElementType::Asset);
$criteria->id = 1;
$asset = $criteria->first();

if ($asset)
    $url = $asset->getUrl('myTransform');

$imgUrl = $image->getUrl('tranformHandle);

...as I understand it that triggers the image to be transformed on-demand if the transform does not already exist.

  • Hum this is what I did but it does not work. I have a problem ok I will try to see in the logs. Commented May 28, 2017 at 5:06
  • OK I found it : got a problem with my permissions on the directory... Commented May 28, 2017 at 5:15
  • Glad you got it working. Commented May 28, 2017 at 5:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.