<p>Yes, it's possible.</p>

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

<pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Asset);
$criteria-&gt;id = 1;
$asset = $criteria-&gt;first();

if ($asset)
{
    $url = $asset-&gt;getUrl('myTransform');
}

$imgUrl = $image-&gt;getUrl('tranformHandle);
</code></pre>

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

CC BY-SA 3.0
2017-05-28T05:06:52.270Z
Hum this is what I did but it does not work. I have a problem ok I will try to see in the logs.
migmaker
CC BY-SA 3.0
2017-05-28T05:15:40.340Z
OK I found it : got a problem with my permissions on the directory...
migmaker
CC BY-SA 3.0
2017-05-28T05:16:29.020Z
Glad you got it working.
Jeremy Daalder
CC BY-SA 3.0
2017-05-27T23:36:24.417Z
2017-05-27T23:36:24.417Z
Jeremy Daalder
<p>How can I trigger an image transform in a Craft plugin?</p>

<plugin-development><image-transforms>
Image transform in a plugin
# Image transform in a plugin

(Asked by: username_0 on 2017-05-27)

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

**Tags:** plugin-development, image-transforms

---

## 1 answers

### Answer by username_1 on 2017-05-27. Score: 3 | Accepted answer

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.

> **Comments:**
> **username_0**: Hum this is what I did but it does not work. I have a problem ok I will try to see in the logs.  
> **username_0**: OK I found it : got a problem with my permissions on the directory...  
> **username_1**: Glad you got it working.  

---

