<p>Yes you can – assets include a <a href="https://docs.craftcms.com/api/v3/craft-elements-asset.html#method-getsrcset" rel="nofollow noreferrer"><code>getSrcSet</code> method</a> which will generate all the requested image sizes and return a <code>srcset</code> string. This method accepts an <a href="https://craftcms.com/docs/3.x/image-transforms.html#defining-transforms-in-your-templates" rel="nofollow noreferrer">image transform</a> which can include the desired output format.</p>
<pre class="lang-twig prettyprint-override"><code>{% set image = entry.someImageField.one() %}
{% set webpTransform = {
    format: 'webp',
    quality: 75,
} %}
&lt;source type=&quot;image/webp&quot; srcset=&quot;{{ image.getSrcSet([800, 1200], webpTransform) }}&quot;&gt;
</code></pre>
<p>Note that in order for this to work, your server needs to have either GD or ImageMagick installed with WebP support.</p>
<p>Check out the documentation on <a href="https://craftcms.com/docs/3.x/image-transforms.html" rel="nofollow noreferrer">Image Transforms</a> for more information.</p>

CC BY-SA 4.0
2022-03-14T22:38:58.433Z
Great, it works perfectly! 
Thanks for the support!

Regards,
Davide
Davide
CC BY-SA 4.0
2022-03-14T08:58:51.437Z
2022-03-14T08:58:51.437Z
MoritzLost
<p>Is possible from a jpg image from an entry field return a serset in webp fomat?
Something like:</p>
<pre><code>&lt;source type=&quot;image/webp&quot; srcset=&quot;800w webp image, 1200w webp image &quot;&gt;
</code></pre>
<p>Because I can convert in web or get the srcset from the original image
but I don't know how to convert the original image and get a srcset.</p>
<p>Thanks in advance and kind regards,
Davide</p>

<image-transforms>
Transform image in webp and get srcset
# Transform image in webp and get srcset

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

Is possible from a jpg image from an entry field return a serset in webp fomat?
Something like:


Because I can convert in web or get the srcset from the original image
but I don't know how to convert the original image and get a srcset.
Thanks in advance and kind regards,
Davide

**Tags:** image-transforms

---

## 1 answers

### Answer by username_1 on 2022-03-14. Score: 4 | Accepted answer

Yes you can – assets include a getSrcSet method which will generate all the requested image sizes and return a srcset string. This method accepts an image transform which can include the desired output format.
{% set image = entry.someImageField.one() %}
{% set webpTransform = {
    format: 'webp',
    quality: 75,
} %}


Note that in order for this to work, your server needs to have either GD or ImageMagick installed with WebP support.
Check out the documentation on Image Transforms for more information.

> **Comments:**
> **username_0**: Great, it works perfectly!  Thanks for the support!  Regards, Davide  

---

