Kirby 3.6.0 and WebP

Hi there,

I am testing the new WebP feature in Kirby 3.6.0. I really love it. I was wondering: How can I force Kirby to also convert images to .webp from images in my content? For example: images uploaded in a content field.


Not quite sure i follow, you can use the thumb() method in your template with the format option for this.

So for example if you have images present from being uploaded before 3.6 upgrade, you can convert like this perhaps:

<?php $image = $page->images()->first(); ?>
<?= $image->thumb(['format' => 'webp']) ?>
<?= $image->thumb(['format' => 'avif']) ?>

You just need a file obect and then you can make it happen :slight_smile:

This should work from a files field:

<?php if($image = $page->yourfieldname()->toFile()): ?>
  <img src="<?= $image->thumb(['format' => 'webp'])->url() ?>" alt="">
<?php endif ?>
1 Like

Thanks for your help and reply.
I mean the images that fall within a kirbytext field. They are still .jpg

<?= kirbytext($page->text()) ?>

Maybe I have to set this in the config?

A standard image KirbyTag renders a full image, not a thumb. So you would have to change the KirbyTag or auto-replace jpeg images with webp via .htacess or some other way.

It basically depends on your image strategy, i.e. if you only want to provide WebP images or depending on whether a browser supports that format etc.

1 Like

Okay I understand! Thank you :slight_smile: