Image Conversion

Hi!

I generally use .webp images in my web-projects and take .jpg as fallback.

It would be a great feature if you could request an image in a specific format eg.

fetch('/api/cockpit/image?token=xxtokenxx', {
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        src: imagePath || asset._id,
        t: webp
    })
})

Maybe even in multiple formats:

fetch('/api/cockpit/image?token=xxtokenxx', {
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        src: imagePath || asset._id,
        t: [webp, jpg]
    })
})

Greetings

You can already convert it on the API call (at least worked for me). All you have to do is pass “mime=image/webp” as a parameter for the API call.

So it would like this (with the encoded URI):

fetch(’/api/cockpit/image?token=xxtokenxx&src=yourImagePath.png&mime=image/webp’, {
method: ‘post’,
headers: { ‘Content-Type’: ‘application/json’ }
})

1 Like

This CMS just keeps giving and giving.

Just keep in mind: unless your code runs server-side releasing the token like that into the wild makes /api/cockpit/image a public endpoint.
But it should be fine as you still have to know the images paths to make the API produce the images.
Just make sure you use a custom key for that token with only access to the image-api-endpoint.

Turns out you can also directly use the image path inline.

<img src="/api/cockpit/image?token=xxtokenxx&src=yourImagePath.png&mime=image/webp&o=1">