How to resize an image

Hi, I have a loop to display a gallery of images.
All the images are in the page folder.
The html for displaying an image is:

<img src="example.gif" alt="Example" width="200" height="100">

Do I have an option in Kirby to specify the width of a specific image in the folder without checking in the code the name of the image and resizing it.

Thanks for any help

You can store such information in the file meta data:

i am not sure i understand your question.

do you want to define a value for a width somewhere and when creating the gallery all images are a) resized and/or b) have their width attribute set to that value?

like @texnixe suggested storing the target width at the files metadata is good idea. it can be read just like any other file field.

actually resizing the image, not just setting the width attribute is done using the $file->resize($width) file method.

using the width attribute is not very flexible in the long run since its very hard for other styles like from css to override it. consider using the style attribute instead. style="width:123px;"

Thanks for this - I’ll give it a try in the morning.
I only need to change a few of the image sizes - not all - how do I check if a file meta data exists for an image?

lets assume you defined gallerywidth as an number field in the file blueprint for your gallery images.

then you do something like this:

<img width="<?= $file->gallerywidth()->isNotEmpty() ? $file->gallerywidth()->toInt() . 'px' : 'auto' ?>" src="...">