Hi there,
how can I make use of picture
tags to provide img
’s with webp files?
WebP support was added with 4.9.0 and I already read the responsive asset manual page.
Therefore, I already know that I can use responsive images via
<img class="post-image"
srcset="{{img_url feature_image size="s"}} 300w,
{{img_url feature_image size="m"}} 600w,
{{img_url feature_image size="l"}} 1000w,
{{img_url feature_image size="xl"}} 2000w"
sizes="(max-width: 1000px) 400px, 700px"
src="{{img_url feature_image size="m"}}"
alt="{{#if feature_image_alt}}{{feature_image_alt}}{{else}}{{title}}{{/if}}"
/>
Which is great. But how do I enhance this to this?
<picture class="post-image"> ↓↓ something like this ↓↓
<source ↓↓↓↓↓↓↓↓↓↓↓
srcset="{{img_url feature_image type="webp" size="s"}} 300w,
{{img_url feature_image type="webp" size="m"}} 600w,
{{img_url feature_image type="webp" size="l"}} 1000w,
{{img_url feature_image type="webp" size="xl"}} 2000w"
sizes="(max-width: 1000px) 400px, 700px"
type="image/webp"
/>
<img
srcset="{{img_url feature_image size="s"}} 300w,
{{img_url feature_image size="m"}} 600w,
{{img_url feature_image size="l"}} 1000w,
{{img_url feature_image size="xl"}} 2000w"
sizes="(max-width: 1000px) 400px, 700px"
src="{{img_url feature_image size="m"}}"
alt="{{#if feature_image_alt}}{{feature_image_alt}}{{else}}{{title}}{{/if}}"
/>
Any help appreciated
PS: In the assets manual page, you could rephrase this sentence:
Responsive images can be defined in the
package.json
file.
To
Responsive images can be defined in the
package.json
file of your current theme.
I searched the package.json for a while until I realized that you probably meant the theme’s package.json file