0

I am evaluating a completely headless setup with kirby. I would like to be able to upload an image in one big size and kirby should generate different sizes of responsive images. (I know this feature from WordPress where this is possible).

I see there is this: https://getkirby.com/docs/guide/templates/resize-images-on-the-fly But this is all php kirby code, and I want just to consume the REST API. So now kirby syntax available. I tried to preconfigure the sizes within site/config/config.php but when uploading a new image, it would not save it in different sizes…

I then thought, maybe it would just generate the specific size the first time the image is requested. I've seen this behaviour with multiple CDNs. But also I did not find any documentation about that.

So what would be the best way to upload an image, and then being able to load a resized version of that image via REST API?

Is there even a possibility? thank you for every input on that.

Cheers

Merc
  • 4,241
  • 8
  • 52
  • 81

1 Answers1

2

Well some time has passed and I learnt a bit more about kirby and how it works. The image is generated on the fly, when executing kirby syntax like $file->resize(720, null, 60)->url() (read more: https://getkirby.com/docs/guide/templates/resize-images-on-the-fly)

So to get images in different sizes via REST API, one can write a custom route where you are responsible of executing these resize commands whenever somebody is consuming this endpoint. A simpler solution would be using the plugin better-rest (https://github.com/robinscholz/better-rest) which does part of it for you already (for example in the better-rest endpoint images are amongst other stuff returned as srcset).

I hope this helps somebody one day. Cheers

Merc
  • 4,241
  • 8
  • 52
  • 81