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 – build remarkable experiences at scale

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