📆 Don't miss our Sanity Showcase virtual meetup on March 20th!

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?

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
Rendering nested block contentJan 18, 2021
Warning: Data for Page Exceeds the Threshold of 128 kBAug 17, 2022
Custom Document Views - Is it Even Possible to Use the Structure Builder?Apr 21, 2022
How to populate a list of values in a Sanity schema using a separate fileSep 6, 2021
How to fetch an array of images using groq in Sanity.ioMay 21, 2023
Is there a way to write a groq query that checks if a boolean is true, and if so, returns an array of referenced documents?...Feb 1, 2021
Error: unable to resolve image URL from source (undefined)Sep 11, 2022
Extracting referenced images from an object array in Sanity.ioMay 17, 2020
Understanding how to use hotspot crop on images in Sanity.ioSep 15, 2020
I can't find the edit button to edit the image... can someone help?Dec 31, 2020

Related contributions

Turbo Start Sanity
- Template

The battle-tested Sanity template that powers Roboto Studio's websites

Go to Turbo Start Sanity

Schema UI - Next.js Sanity Starter
- Template

A Next.js starter template with Next.js 15, Tailwind CSS, shadcn/ui, and Sanity CMS with Live Editing. Get production-ready React components with matching Sanity schemas and queries. Build dynamic pages faster while keeping full control over customization.

Serge Ovcharenko
Go to Schema UI - Next.js Sanity Starter

The Swaddle
- Made with Sanity

A new brand identity to represent a more mature company, to signify The Swaddle’s evolution from publisher to production house, combined with an easier to navigate platform that can surface multiple content types - drawing readers through The Swaddle’s content offering.

Nightjar
Go to The Swaddle