I use some animated GIF’s on Kirby 3 and 4 websites.
While I would like the PNG’s and JPG’s to be converted to WebP, the GIF’s should not be touched. How can I configure the driver to not convert GIF’s?
We will need more context of what you’re doing currently. Converting them on upload via blueprint? In a hook? In your templates via ->thumbs()
method? Please be as concrete as possible, the easier it is to help.
The thumbnails are converted via the config file.
I don’t mind if the GIF’s are not animated in the blueprint.
I’m using the <?= $image->srcset([300, 800, 1024, 1440, 2048]) ?>
inside the image template. If I don’t specify that thumbs should be converted to webp
they stay GIF’s yet no longer animated. (I can replace them manually inside the media folder with scaled animated GIF’s). But since the GIF is already optimised and rather small, I would just like to configure the image driver to not touch GIF’s at all.
GD is unable to resize GIF files and retain the animation, however, IM is capable doing it. I would recommend switching to IM. Im not sure how to prevent it from touching GIFs.
I was hoping, that there was a way to exclude a format from being converted in the configuration. Ideally uploaded PNG’s and JPG’s are converted to .webp, only GIF’s stay what they are. The scaled GIF files are often getting bigger, because the original is optimised.
If I use Image Magic with .webp conversion on, the GIF’s become static .webp
(But I’m repeating myself here)
Where did you define that PNGs and JPGs should be converted to WebP?
Have you defined an srcset with ‘format’ => ‘webp’
in your config.php?
<?= $image->srcset([300, 800, 1024, 1440, 2048]) ?>
This will cause the image to be recalculated, which you don’t want, at least not for GIF images.
Im not sure how to prevent it from touching GIFs.
You can achieve this with a query. This inserts the original:
// If the file is a GIF, pass it off as the original.
<?php if($image->mime() === 'image/gif'): ?>
<?= $image->url() ?>
// Otherwise, recalculate the file:
<?php else: ?>
<?= $image->srcset([300, 800, 1024, 1440, 2048]) ?>
<?php endif ?>
(Tested with Kirby Starterkit)
Thanks @GB_DESIGN, this is really smart.
Why did I not think to solve this on the php level in the image snippet
Highly appreciated!