I’m looking for a way to have images inserted using the (image: image.jpg) tag in the panel use a pre-defined thumb preset by default. Preferably, users should not have to specify any width or height manually for the image. I’d also like to make the tag output HTML with the srcset attribute.
Any tips as to where I should start looking to accomplish this? Thank you!
I understand it’s all or nothing with the image tag. I was wondering if there was solution which didn’t involve duplicating Kirby code, with related issues of maintainability and the like… something like a built-in option. But overriding the image tag is not a big deal. I replaced this code (from the image tag):
// use the file url if available and otherwise the given url
$url = $file ? $file->url() : url($url);
… with this:
if ($file) {
if ($tag->attr('width') || $tag->attr('height')) {
// Explicit width or height, use file URL
$url = $file->url();
} else {
// Use the thumb URL
$url = $file->thumb('article')->url();
}
} else {
// Use given URL
$url = url($url);
}
… with a thumb preset called “article”, and it seems to do the trick with regards to using thumb presets for the images. I’ll get back to the srcset part later.