Blueprints (files) suggestions; fields for kirbytext tags & image density

Hello everyone,

I’m working on a kirbytext image method and it got me thinking about using image fields to add an alt text and caption to an image. Personally I prefer to add metadata to a file instead of using kirbytext. It would be nice if I could define a field for the alt-text and a caption in the files section of a blueprint:

      label: Caption
      type: text
  caption: my-caption-field

Now I can add a caption text to the image itself, the same would apply to an alt tag.

Another option that would be nice is an image density setting that is used to resize images using attribute tags:

  density: 2

This is similar to css @media(device-pixel-ratio), if its set to 2 as in the example the image width and height are divided by 2 before being set as the corresponding img attributes (or $file->width()). This would make it really easy to use hidpi/retina images with Kirby.

Optionally the image could be served with slightly more compression (if the density is higher than 1) on the fly because small artefacts will get resolved by the higher resolution.

Cheers :slight_smile:

You already can to this:

      label: Caption
      type: textarea

I know about file fields for but this way alone its content won’t be added to a kirbytext image object, for that I need to add an inline caption: (image: example.jpg caption: 'inline caption'). My proposition is that a caption field can be specified to get it from the image file itself (the last line in the code example).

For now I added a block to the kirbytext image method to take the caption field by default which acts in the same way:

// modified: try to get a caption from the image object
if($file) {

  if(empty($caption) and $file->caption() != '') {
    $caption = $file->caption();


Well, this is not really a files setting. I think the better option here is to create a custom image kirbytag for such purposes. Also, the syntax you suggested can be mistaken for a reference to a global field definition.

Also, the Kirbytags don’t know anything about blueprint settings, anyway.

I see, the alt attribute does capture the alt field (if any) when no alt tag is set (kirby/extensions/tags.php:95):

if(empty($alt) and $file->alt() != '') {
  $alt = $file->alt();

Perhaps this can be added for a caption as well (basically make my modification above default behaviour).

As I said, as long as such a feature does not exist, you can easily make a copy of the image tag, put it into /site/tags/image.php and make all the adjustments you need, including the density stuff. No need to fiddle with the core files. You custom tag will thus overwrite the native tag.

@n8n Did you ever get around to making a custom image tag that will print out image captions from their file metadata?