Go Behind the Experience to see how Tecovas brings the West to life with Sanity 🀠 July 18th

How to Set Aspect Ratios on Images?

5 replies
Last updated: Sep 7, 2020
Hey, quick one - is there anyway I can get info about the dimensions of image that are being uploaded? Want to use them to set some aspect ratio styling. Thanks!
Sep 7, 2020, 5:03 PM
Hey Callum, that information is stored in the image asset object under
. You can query it like this for example:
*[_type == "post"] {
    "dimensions": metadata.dimensions
Sep 7, 2020, 5:08 PM
Great thank you! My images are somewhat more nested than that but will see if I can get it to work
Sep 7, 2020, 6:24 PM
Let me know if you need any help navigating the nesting πŸ™‚
Sep 7, 2020, 6:42 PM
Got there in the end just took a bit of groq revision πŸ˜… – thanks again!
Sep 7, 2020, 7:14 PM
Awesome - and we approve of groq revisions πŸ€“
Sep 7, 2020, 7:17 PM

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?