sanity-io / sanity

Sanity Studio – Rapidly configure content workspaces powered by structured content
https://www.sanity.io
MIT License
5.33k stars 429 forks source link

Cropping issue with the image API #4036

Open richgcook opened 1 year ago

richgcook commented 1 year ago

Describe the bug

I'm having an issue with Sanity's image builder methods. An uploaded image, for example, is https://cdn.sanity.io/images/e00m9tq7/production/930c255d2b03f5d87ad8fcaf4d478a65d7489caa-3024x4032.jpg and with my builder methods it outputs https://cdn.sanity.io/images/e00m9tq7/production/930c255d2b03f5d87ad8fcaf4d478a65d7489caa-3024x4032.jpg?w=3200&q=82&fit=clip&auto=format which is heavily cropping the image and I can't understand why.

A different image, using the same builder methods, doesn't crop at all https://cdn.sanity.io/images/e00m9tq7/production/fd0d909075189de9b4cf3630a74d7d3042da29c4-2002x3000.jpg?w=3200&q=82&fit=clip&auto=format

Ultimately it looks like the Sanity API is doing something unexpected here.

I mentioned all this in the Slack channel and was instructed to open up a bug report https://sanity-io-land.slack.com/archives/C9Z7RC3V1/p1670599826352319

Expected behavior

This should ostensibly provide the image in its original dimensions, but it is cropping in significantly.

Which versions of Sanity are you using?

@sanity/cli 2.35.0 (latest: 3.1.4) @sanity/base 2.30.1 (latest: 2.35.2) @sanity/color-input 2.30.1 (latest: 3.0.1) @sanity/components 2.14.0 (up to date) @sanity/core 2.30.1 (latest: 2.35.0) @sanity/dashboard 2.30.1 (latest: 3.1.1) @sanity/default-layout 2.30.1 (latest: 2.35.2) @sanity/default-login 2.30.1 (latest: 2.35.2) @sanity/desk-tool 2.30.1 (latest: 2.35.2) @sanity/orderable-document-list 0.0.4 (latest: 1.0.2) @sanity/vision 2.30.1 (latest: 3.1.4)

What operating system are you using?

macOS Monterey 12.3.1

Which versions of Node.js / npm are you running?

8.11.0 v16.15.1

dcilke commented 1 year ago

Hi @richgcook, thanks for opening an issue (and apologies for taking so long to respond). This is an interesting bug, I've opened a ticket internally and will let you know when we get it resolved.

queuedq commented 9 months ago

I stumbled on this same issue and it seems to be a problem with Sanity not respecting EXIF orientation tag.

When I take a vertical photo on my iphone, the photo data is actually saved in landscape orientation. EXIF orientation tag specifies the orientation when the photo was taken (e.g. 90 clockwise) so that we can see the photo vertically oriented.

It seems like Sanity didn't take this into account and crops the photo according to "original" landscape dimensions.

queuedq commented 9 months ago

I found a workaround. The bug seems to happen only with fit=clip paratemter. Providing fit=max instead fixes the issue.