Adding custom class to an image

How do I add a custom class to an image?

I’ve tried by adding a text file to the same folder as the image for example"
image.jpg with text file image.jpg.txt
in there
(image: image.jpg class: custom)

But it won’t work and keeps the class as ‘Thumbnail’. Is there a different way or something else I should do?

The (image: image.jpg class: custom) is the markdown code for inserting an image into a textarea field.

If you want to insert this image directly into a template/snippet you will have to create a field. If you call this field “class” you can output the class in PHP like that:

<img class="<?= $page->images()->first()->class() ?>" src="<?= $page->images()->first()->url() ?>" />

The image.jpg.txt would then look like that:

class: custom

Does that help you?

If you simply want to insert the image into the Markdown/Kirbytext content of a page, you can use the (image: image.jpg class: custom) syntax you posted, but this belongs inside the Kirbytext of the page you want to display the image in, not inside the image meta file.