How to output square image without cropping using Sanity image client library?

9 repliesLast updated: Nov 29, 2025

Hey how do I always output a rectangle image using the image client library? I have pack shots of products that are always in a random size with a transparent background. I want the output image to be square though in a fixed size, where the product is fully visible. For some reason the image is always cropped, no matter what property I use for the “fit” parameter.
Original image:
https://cdn.sanity.io/images/mxqn1342/develop/cf033ca4c0dac8c511d2603912dc5bae94ab6008-1524x2200.png Output image using client library (
product.image.size(800, 800).fit('fillmax').auto('format').url()
): https://cdn.sanity.io/images/mxqn1342/develop/cf033ca4c0dac8c511d2603912dc5bae94ab6[…]0.png?rect=0,338,1524,1524&w=800&h=800&fit=fillmax&auto=format Output image using client library (
product.image.size(800, 800).fit('clip').auto('format').url()
): https://cdn.sanity.io/images/mxqn1342/develop/cf033ca4c0dac8c511d2603912dc5bae94ab6[…]2200.png?rect=0,338,1524,1524&w=800&h=800&fit=clip&auto=format
Any ideas?
AI Update

Looking at your URLs, I can see the issue - there's a rect=0,338,1524,1524 parameter being applied, which means Sanity is using the crop/hotspot data stored with your image document. This is overriding your fit parameter and causing the cropping you're seeing.

The solution is to use the ignoreImageParams() method in the image URL builder to tell Sanity to ignore any crop or hotspot data stored with the image:

product.image
  .ignoreImageParams()
  .size(800, 800)
  .fit('fillmax')
  .bg('transparent')
  .auto('format')
  .url()

The ignoreImageParams() method removes any stored crop/hotspot settings, so your fit parameter will actually work as intended.

For your use case with transparent product shots that need to remain fully visible in a square output, I'd recommend using fit('fillmax') combined with a transparent background:

product.image
  .ignoreImageParams()
  .size(800, 800)
  .fit('fillmax')
  .bg('transparent')
  .auto('format')
  .url()

Here's what the different fit modes do when you're not being overridden by crop data (from the image transformations documentation):

For the transparent background padding, you can use bg('transparent') or specify a hex color like bg('ffffff') for white.

The key takeaway: Whenever you have existing crop/hotspot data on an image field but want to control the output differently, use ignoreImageParams() first in your chain to override the stored image parameters.

Show original thread
9 replies

Was this answer helpful?

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.

Related contributions