Thumbnail URL for each entry in collection inside response


#1

Hello,
I’ve started using Cockpit for my single page app, which is a simple portfolio: title, description, gallery. I have kind of main page, with small thumbnail of each project.

What I need is to attach url to thumbnail of specific size, for each entry, INSIDE response of ‘/api/collections/get…’. I don’t want to use ‘/api/cockpit/image…’, because as far as I understand I would have to use it X times in a row.

I know PHP a bit and I’m not afraid to mess a bit inside files, with a little help and advice where to look for.

I see it like this: I have a field of Image type with defined name (ie. ‘featuredImage’). Then I put inside PHP rules to create thumbnail of this particular image, put its URL inside entry data (ie. ‘_thumbnailURL’) and attach this field to the API response every time.

Thanks in advance for any help or advice.
Igor


#2

Why don’t you want to use it? what is wrong with this approach:

<img src="/api/cockpit/image?token=xxtokenxx&src=path&w=200&h=200&o=1">

#3

Have you looked to the ImageStyles addon - https://github.com/pauloamgomes/ImageStyles ? It provides way a simple way to define styles (e.g. thumbnail, banner, etc…) and the corresponding image urls will be returned automatically.


#4

@pauloamgomes, this looks promising. I’m gonna try it.

@artur, I might have misunderstood the idea earlier, I was thinking that this approach will give me only the urls, then I need to send request again for the image itself in the .
However it would be nice to receive one complex response of entries with their image urls and get rid of putting token and full path again in each img.

Thanks for replies.