Ghost’s automatic image resize also supports converting formats, including AVIF and WEBP. But your theme “should ask” for it. It’s not done on upload time. For example, in Source theme you can see a file named partials/feature-image.hbs
with content:
{{#if feature_image}}
<figure class="gh-article-image">
<img
srcset="{{img_url feature_image size="s"}} 320w,
{{img_url feature_image size="m"}} 600w,
{{img_url feature_image size="l"}} 960w,
{{img_url feature_image size="xl"}} 1200w,
{{img_url feature_image size="xxl"}} 2000w"
sizes="(max-width: 1200px) 100vw, 1120px"
src="{{img_url feature_image size="xl"}}"
alt="{{#if feature_image_alt}}{{feature_image_alt}}{{else}}{{title}}{{/if}}"
>
{{#if feature_image_caption}}
<figcaption>{{feature_image_caption}}</figcaption>
{{/if}}
</figure>
{{/if}}
This code provides different sizes of the same feature image according to the browser viewport size, by keeping original format. But img_url
also has format
option. So you can do this if you always want to use webp
format on your featured images:
{{#if feature_image}}
<figure class="gh-article-image">
<img
srcset="{{img_url feature_image size="s" format="webp"}} 320w,
{{img_url feature_image size="m" format="webp"}} 600w,
{{img_url feature_image size="l" format="webp"}} 960w,
{{img_url feature_image size="xl" format="webp"}} 1200w,
{{img_url feature_image size="xxl" format="webp"}} 2000w"
sizes="(max-width: 1200px) 100vw, 1120px"
src="{{img_url feature_image size="xl" format="webp"}}"
alt="{{#if feature_image_alt}}{{feature_image_alt}}{{else}}{{title}}{{/if}}"
>
{{#if feature_image_caption}}
<figcaption>{{feature_image_caption}}</figcaption>
{{/if}}
</figure>
{{/if}}
But, there is even a better option: Providing best format according to browser support. If you want to use avif format if visitor’s browser support then use webp (or original format) as fallback you can use picture
HTML element with source
. (Don’t miss including img
tag inside picture
)
{{#if feature_image}}
<figure class="gh-article-image">
<picture>
<source srcset="{{img_url feature_image size="s" format="avif"}} 320w,
{{img_url feature_image size="m" format="avif"}} 600w,
{{img_url feature_image size="l" format="avif"}} 960w,
{{img_url feature_image size="xl" format="avif"}} 1200w,
{{img_url feature_image size="xxl" format="avif"}} 2000w"
type="image/avif"
>
<img srcset="{{img_url feature_image size="s" format="webp"}} 320w,
{{img_url feature_image size="m" format="webp"}} 600w,
{{img_url feature_image size="l" format="webp"}} 960w,
{{img_url feature_image size="xl" format="webp"}} 1200w,
{{img_url feature_image size="xxl" format="webp"}} 2000w"
sizes="(max-width: 1200px) 100vw, 1120px"
src="{{img_url feature_image size="xl" format="webp"}}"
alt="{{#if feature_image_alt}}{{feature_image_alt}}{{else}}{{title}}{{/if}}"
>
</picture>
{{#if feature_image_caption}}
<figcaption>{{feature_image_caption}}</figcaption>
{{/if}}
</figure>
{{/if}}
You can also add more source definitions for sure (like try avif, then webp then jpeg).
But be aware, then you define more variants, eventually with your visitors’ requests, you will have more image files for each source image in your storage.