Unlock seamless workflows and faster delivery with our latest releases- get the details

How to Generate an Image URL Using Auto=Format

6 replies
Last updated: May 6, 2022
Hi, quick question:when generating a url for my images in the front-end there’s the option to use
auto=format
to automatically use
webp
as image format if the browser supports it. is there a way to specify a fallback format (eg i want to use
jpg
if the original image file is uploaded as
png
) if the browser doesn’t?
May 5, 2022, 12:12 PM
Nah. If you want to use JPG because your image doesn’t need transparency, upload it as JPG in the first place instead of PNG. 🙂 The tool cannot know whether you need the transparency or not, and there is no argument to enforce a format as far as I know.
May 5, 2022, 12:13 PM
you can force formats with the urlBuilder
$urlFor(image.asset).format('jpg')
and a lot of clients just want to be able to upload images no matter the format. transparency doesn’t matter in most cases. (but i would generally agree
🙂)
May 5, 2022, 12:34 PM
Oh that's neat, I forgot about the URL builder. I wasn't aware, apologies. Thanks Bastian! ❤️
May 5, 2022, 12:48 PM
Not that I am aware of
user U
, no. Outside of the
auto
or
fm
URL parameters there isn't anything like what you are asking for to my knowledge.
May 5, 2022, 11:22 PM
You may be able to handle this depending on use case through client side logical conditionals, but this is not ideal from what you are seemingly looking for 🙇‍♂️
May 5, 2022, 11:28 PM
it probably doesn’t even matter anyway. the 2.5 people still using a browser that doesnt support webgl probably have different problems than downloading 200kb more because they are being served a PNG instead of a JPG… 😄 thanks
May 6, 2022, 10:09 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?