<p>Sortof – you can find out what an image’s width would be with a transform applied to it via AssetFileModel’s - <a href="http://buildwithcraft.com/docs/templating/assetfilemodel#getWidth">getWidth()</a> and <a href="http://buildwithcraft.com/docs/templating/assetfilemodel#getHeight">getHeigth()</a></p>

<pre><code>&lt;img src="
    {%- if image.getWidth(transform) &gt; 970 -%}
        {{ image.getUrl(transform) }}
    {%- else -%}
        {{ image.url }}
    {%- endif %}" alt="{{ image.title }}" /&gt;
</code></pre>

<p>And for extra cleanliness points, you can update the code to use <a href="http://buildwithcraft.com/docs/templating/assetfilemodel#setTransform">setTransform()</a> instead of jumbling all that code into your <code>&lt;img&gt;</code> tag:</p>

<pre><code>{% if image.getWidth(transform) &gt; 970 %}
    {% do image.setTransform(transform) %}
{% endif %}

&lt;img src="{{ image.url }}" alt="{{ image.title }}" /&gt;
</code></pre>

CC BY-SA 3.0
2014-06-12T00:26:34.343Z
Thanks Brandon! I award you a correct answer, 12 gold coins, and a stack Exchange invisibility cloak. Once you reach 7 merit badges you will be elegible for meta.meta.meta.craftcms.stackexchange.com. (currently in private beta).
James Muspratt
CC BY-SA 3.0
2014-06-12T00:40:01.657Z
That's so meta.
Jeremy Gimbel
CC BY-SA 3.0
2014-06-12T00:18:00.650Z
2014-06-12T00:18:00.650Z
Brandon Kelly
<p>Can I extract a transform's settings from its handle? I'm trying to avoid upscaling images using the workaround, and I'd like to set my transform handle dynamically within some conditionals. (see <a href="https://plus.google.com/115463622553757255119/posts/M4AWTz9PKPi">this link</a>).</p>

<p>Say I'm looping through a matrix field as in the example below, using a dropdown variable to determine which transform is best. When outputting the image I'd like to replace that '970' with pixel width specific to that the asset transform. I'm sure this is wrong, but I'm imagining something like <code>getTransform(transform).width.</code></p>

<pre><code>{% if block.formation == 'twins' %} 
    {% set transform = 'medium' %}
{% else%}
    {% set transform = 'large' %}
{% endif %}

&lt;figure&gt;
  &lt;img src="{% if image.getWidth() &gt; 970 %}{{ image.getUrl(transform) }}{% else %}{{ image.url }}{% endif %}" alt="{{ image.title }}" /&gt;
&lt;/figure&gt;
</code></pre>

<image-transforms>
Transform Info from Handle?
# Transform Info from Handle?

(Asked by: username_0 on 2014-06-12)

Can I extract a transform's settings from its handle? I'm trying to avoid upscaling images using the workaround, and I'd like to set my transform handle dynamically within some conditionals. (see this link).
Say I'm looping through a matrix field as in the example below, using a dropdown variable to determine which transform is best. When outputting the image I'd like to replace that '970' with pixel width specific to that the asset transform. I'm sure this is wrong, but I'm imagining something like getTransform(transform).width.
{% if block.formation == 'twins' %} 
    {% set transform = 'medium' %}
{% else%}
    {% set transform = 'large' %}
{% endif %}

**Tags:** image-transforms


---

## 1 answers

### Answer by username_1 on 2014-06-12. Score: 20 | Accepted answer

Sortof – you can find out what an image’s width would be with a transform applied to it via AssetFileModel’s - getWidth() and getHeigth()


And for extra cleanliness points, you can update the code to use setTransform() instead of jumbling all that code into your  tag:
{% if image.getWidth(transform) > 970 %}
    {% do image.setTransform(transform) %}
{% endif %}

> **Comments:**
> **username_0**: Thanks Brandon! I award you a correct answer, 12 gold coins, and a stack Exchange invisibility cloak. Once you reach 7 merit badges you will be elegible for meta.meta.meta.craftcms.stackexchange.com. (currently in private beta).  
> **username_2**: That's so meta.  

---

