Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-14T22:38:58.433Z
Answers.Text: Great, it works perfectly! 
  Thanks for the support!
  
  Regards,
  Davide
Answers.UserDisplayName: Davide
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-14T08:58:51.437Z
Answers.LastActivityDate: 2022-03-14T08:58:51.437Z
Answers.UserDisplayName: MoritzLost
Body: <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>
  
Tags: <image-transforms>
Title: Transform image in webp and get srcset
ThreadText: # 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:
  
  ```
  <source type="image/webp" srcset="800w webp image, 1200w webp image ">
  
  ```
  
  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,
  username_0
  
  **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](https://docs.craftcms.com/api/v3/craft-elements-asset.html#method-getsrcset) which will generate all the requested image sizes and return a `srcset` string. This method accepts an [image transform](https://craftcms.com/docs/3.x/image-transforms.html#defining-transforms-in-your-templates) which can include the desired output format.
  
  ```twig
  {% set image = entry.someImageField.one() %}
  {% set webpTransform = {
      format: 'webp',
      quality: 75,
  } %}
  <source type="image/webp" srcset="{{ image.getSrcSet([800, 1200], webpTransform) }}">
  
  ```
  
  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](https://craftcms.com/docs/3.x/image-transforms.html) for more information.
  
  > **Comments:**
  > **username_0**: Great, it works perfectly!  Thanks for the support!  Regards, username_0  
  
  ---
  
  