<p>Like Brad says, you'd need to write a custom plugin – specifically, one that provides a <a href="http://buildwithcraft.com/docs/plugins/variables" rel="nofollow">Template Variable</a> class exposing the AssetTransformsService's <a href="https://buildwithcraft.com/classreference/services/AssetTransformsService#getTransformByHandle-detail" rel="nofollow"><code>getTransformByHandle</code></a> method.</p>

<p>The variable class could look something like this:</p>

<pre><code>class MyPluginVariable
{

    public function imageTransformExists($handle)
    {
        // Returns null if transform doesn't exist
        return craft()-&gt;assetTransforms-&gt;getTransformByHandle($handle);
    }

}
</code></pre>

<p>Then, you'd be able to test for named image transforms in your templates like this:</p>

<pre><code>{% if craft.myPlugin.imageTransformExists('thumb') %}
    ...
{% endif %}
</code></pre>

<p>If you're not familiar with plugin development, it might be useful to use the <a href="https://github.com/lindseydiloreto/craft-businesslogic" rel="nofollow">Business Logic plugin</a> as a starting point – it even has a Variable class which you could just drop the above <code>imageTransformExists</code> method into.</p>

CC BY-SA 3.0
2015-10-01T08:39:33.790Z
Thank you very much for the detailed answer 'mmikkel'. Looking into it a little further, it does make sense as to why there isn't a native template-side method for this. As Brad mentions, there are fallbacks already in place. Fortunately for me, this is still going to be of use as I plan to dynamically create this image transform onAfterInstall() on the condition it doesn't already exist.
Mark Notton
CC BY-SA 3.0
2015-09-29T23:22:23.183Z
2015-09-29T23:22:23.183Z
Mats Mikkel Rummelhoff
<p>Nothing native, but it could probably be pulled off with a custom <a href="http://buildwithcraft.com/docs/plugins/introduction" rel="nofollow">plugin</a>.</p>

<p>But just to be clear, if a transform currently doesn't exist then Craft will automatically create it on that request, so the code you shared is pretty much already happening behind the scene.</p>

CC BY-SA 3.0
2015-09-29T17:43:51.407Z
2015-09-29T17:43:51.407Z
Brad Bell
<p>Is there an elegant way to check if an image transform exists?</p>

<pre><code>{% if craft.imageTransformExists('thumb') %}
  &lt;img src="{{asset.getUrl(thumb)}}" alt="Image"&gt;
{% else %}
  This image transform doesn't exists, please create it
{% endif %}
</code></pre>

<image-transforms>
How to check if an Image Transform exists?
# How to check if an Image Transform exists?

(Asked by: username_0 on 2015-09-29)

Is there an elegant way to check if an image transform exists?
{% if craft.imageTransformExists('thumb') %}
  
{% else %}
  This image transform doesn't exists, please create it
{% endif %}

**Tags:** image-transforms


---

## 2 answers

### Answer by username_1 on 2015-09-29. Score: 4 | Accepted answer

Like Brad says, you'd need to write a custom plugin – specifically, one that provides a Template Variable class exposing the AssetTransformsService's getTransformByHandle method.
The variable class could look something like this:
class MyPluginVariable
{

    public function imageTransformExists($handle)
    {
        // Returns null if transform doesn't exist
        return craft()->assetTransforms->getTransformByHandle($handle);
    }

}

Then, you'd be able to test for named image transforms in your templates like this:
{% if craft.myPlugin.imageTransformExists('thumb') %}
    ...
{% endif %}

If you're not familiar with plugin development, it might be useful to use the Business Logic plugin as a starting point – it even has a Variable class which you could just drop the above imageTransformExists method into.

> **Comments:**
> **username_0**: Thank you very much for the detailed answer 'mmikkel'. Looking into it a little further, it does make sense as to why there isn't a native template-side method for this. As Brad mentions, there are fallbacks already in place. Fortunately for me, this is still going to be of use as I plan to dynamically create this image transform onAfterInstall() on the condition it doesn't already exist.  

---

### Answer by username_2 on 2015-09-29. Score: 3

Nothing native, but it could probably be pulled off with a custom [plugin](http://buildwithcraft.com/docs/plugins/introduction).

But just to be clear, if a transform currently doesn't exist then Craft will automatically create it on that request, so the code you shared is pretty much already happening behind the scene.


---

