<h3>Craft 4 PHP</h3>
<pre><code>$transforms = Craft::$app-&gt;getImageTransforms()-&gt;getAllTransforms();
</code></pre>
<h3>Craft 3 PHP</h3>
<pre><code>$transforms = Craft::$app-&gt;getAssetTransforms()-&gt;getAllTransforms();
foreach($allTransforms as $transform){
    echo $asset-&gt;getUrl($transform-&gt;handle);
}
</code></pre>
<h3>Craft 3 Twig</h3>
<pre><code>{% set allTransforms = craft.app.getAssetTransforms.getAllTransforms() %}
{% for transform in allTransforms %}            
    {{ asset.getUrl(transform.handle) }}
{% endfor %}
</code></pre>
<h3>Craft 2 PHP</h3>
<pre><code>$allTansforms = craft()-&gt;assetTransforms-&gt;getAllTransforms();
</code></pre>
<h3>Craft 2 Twig</h3>
<p>You'll need a plugin for this because you don't have access to that component</p>
<pre><code>{% set allTransforms = craft.pluginHandle.getAllAssetTransforms %}
</code></pre>
<p>And in your <code>PluginVariable</code></p>
<pre><code>public function getAllAssetTransforms(){
    return craft()-&gt;assetTransforms-&gt;getAllTransforms();
}
</code></pre>

CC BY-SA 3.0
2018-04-20T13:10:24.940Z
I think for Craft 3 Twig, it should be {{ asset.getUrl(transform.handle) }}. I tried to edit your post, but I need to edit at least 6 characters ...
obs
CC BY-SA 4.0
2022-08-30T13:20:45.733Z
There is a API change in Craft 4, so it become `Craft::$app->getImageTransforms()->getAllTransforms();`
NLemay
CC BY-SA 4.0
2018-03-13T12:16:59.347Z
2022-08-30T13:44:38.950Z
2022-08-30T13:44:38.950Z
Robin Schambach
<p>Is there a way to get all available image transforms in a template?
I would like to generate the <code>srcset</code> for responsive images programmatically.</p>

<p>I thought of creating a macro for that but haven't found any information about how to loop over all the registered image transforms.</p>

CC BY-SA 3.0
2018-04-21T21:28:33.440Z
You might want to get out the [ImageOptimize](https://github.com/nystudio107/craft-imageoptimize) plugin; it has an OptimizedImages field that will pre-generate the `srcset` for you and create all of the images on Asset save time, so the frontend performance is optimal.
andrew.welch
CC BY-SA 3.0
2018-04-24T10:42:16.753Z
Another approach is is the [Picture](https://github.com/marionnewlevant/craft-picture) plugin, where you define the transforms for a picture style in a config file.
Marion Newlevant
<assets><image-transforms><macro><responsive-images>
Get all available asset transforms
# Get all available asset transforms

(Asked by: username_0 on 2018-03-13)

Is there a way to get all available image transforms in a template?
I would like to generate the `srcset` for responsive images programmatically.

I thought of creating a macro for that but haven't found any information about how to loop over all the registered image transforms.

**Tags:** assets, image-transforms, macro, responsive-images

> **Comments:**
> **username_1**: You might want to get out the [ImageOptimize](https://github.com/nystudio107/craft-imageoptimize) plugin; it has an OptimizedImages field that will pre-generate the `srcset` for you and create all of the images on Asset save time, so the frontend performance is optimal.  
> **username_2**: Another approach is is the [Picture](https://github.com/marionnewlevant/craft-picture) plugin, where you define the transforms for a picture style in a config file.  

---

## 1 answers

### Answer by username_3 on 2018-03-13. Score: 3 | Accepted answer

Craft 4 PHP
$transforms = Craft::$app->getImageTransforms()->getAllTransforms();

Craft 3 PHP
$transforms = Craft::$app->getAssetTransforms()->getAllTransforms();
foreach($allTransforms as $transform){
    echo $asset->getUrl($transform->handle);
}

Craft 3 Twig
{% set allTransforms = craft.app.getAssetTransforms.getAllTransforms() %}
{% for transform in allTransforms %}            
    {{ asset.getUrl(transform.handle) }}
{% endfor %}

Craft 2 PHP
$allTansforms = craft()->assetTransforms->getAllTransforms();

Craft 2 Twig
You'll need a plugin for this because you don't have access to that component
{% set allTransforms = craft.pluginHandle.getAllAssetTransforms %}

And in your PluginVariable
public function getAllAssetTransforms(){
    return craft()->assetTransforms->getAllTransforms();
}

> **Comments:**
> **username_0**: I think for Craft 3 Twig, it should be {{ asset.getUrl(transform.handle) }}. I tried to edit your post, but I need to edit at least 6 characters ...  
> **username_4**: There is a API change in Craft 4, so it become `Craft::$app->getImageTransforms()->getAllTransforms();`  

---

