Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

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
metadata.dimensions
. You can query it like this for example:
*[_type == "post"] {
  _id,
  "image":image.asset->
  {
    "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?