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


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.

|improve this answer|||||
  • Hum this is what I did but it does not work. I have a problem ok I will try to see in the logs. – migswd May 28 '17 at 5:06
  • OK I found it : got a problem with my permissions on the directory... – migswd May 28 '17 at 5:15
  • Glad you got it working. – Jeremy Daalder May 28 '17 at 5:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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