Retrieving image metadata with `getImageAsset` in Sanity and modifying queries to include metadata.
Based on the information I found, getImageAsset from @sanity/asset-utils only returns basic metadata that's always included by Sanity, which is why you're only seeing dimensions. The blurHash, lqip, and palette fields are not automatically returned by this utility function, even though they're generated by default when you upload images.
Here's what's happening:
The Difference Between Schema Options and Querying
The schema metadata options (like metadata: ['blurhash', 'lqip', 'palette']) control what gets generated during upload, but they don't automatically appear when you use getImageAsset. This utility function only extracts what's embedded in the asset reference itself.
What getImageAsset Returns
The @sanity/asset-utils package's getImageAsset function only provides:
- dimensions (width/height)
- hasAlpha
- isOpaque
- Basic asset information (format, ID)
These are the fields that are always included and cannot be disabled.
How to Get blurHash and Other Metadata
To access blurHash, lqip, palette, and other metadata, you need to explicitly query for it using GROQ. You can't get it from @sanity/asset-utils alone. Here's how:
// In your GROQ query
*[_type == "yourDocType"] {
image {
...,
asset-> {
_id,
url,
metadata {
dimensions,
blurHash,
lqip,
palette
}
}
}
}For nested or complex structures (like a page builder), you'd use:
*[_type == "caseStudy"] {
pageBuilder[] {
...,
media_item[] {
...,
image {
...,
asset->
}
}
}
}The asset-> syntax fetches the complete asset document, including all its metadata.
Why This Matters
The confusion comes from the fact that Sanity generates blurHash, lqip, and palette by default, but these live in the asset document's metadata, not in the image reference itself. The @sanity/asset-utils package works with the reference string (like image-abc123-1920x1080-jpg), which only contains dimensions, format, and asset ID—not the full metadata.
So you'll need to update your queries to include asset-> or asset->metadata wherever you need that additional metadata for your React image component. As shown in this community answer, you'll want to modify all your queries to explicitly request the metadata you need.
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.