New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
resize()
does not properly handle orientation
metadata
#4047
Comments
Since Sharp uses libvips for image processing, I went ahead and tried it out natively as well. Running libvips from the command line, the issue is not present and orientation is handled correctly. $ vips resize bugged-in.jpg out.jpg 0.1 So it seems like the issue stems from Sharp. |
Please see #2297 (comment) |
@lovell Thanks for the hint, that is a functional workaround for the problem. However, I would argue that this is fundamentally still a bug. If you think about it from a layman's perspective, when you open an image in paint and change its size, you wouldn't expect it to suddenly become rotated — likewise here. While I understand the technical rationale behind it, I think from an end user perspective it doesn't make sense as the default. Intuitively, rotating by zero degrees should be a no-op, it shouldn't be a prerequisite for resizing images. That being said, I'm sure you have good reasons for the design choices and I'm just a random developer doing a drive-by on your library. Just my two cents for thought. |
sharp is a library not a UI. It will not rotate images unless told to. The documented default behaviour is to remove EXIF metadata. |
I hope this information helped. Please feel free to re-open with more details if further assistance is required. |
Possible bug
Is this a possible bug in a feature of sharp, unrelated to installation?
npm install sharp
completes without error.node -e "require('sharp')"
completes without error.If you cannot confirm both of these, please open an installation issue instead.
Are you using the latest version of sharp?
sharp
as reported bynpm view sharp dist-tags.latest
.If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.
If you are using another package which depends on a version of
sharp
that is not the latest, please open an issue against that package instead.What is the output of running
npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp
?What are the steps to reproduce?
Given a certain jpg file (attached below) that uses orientation metadata to orient the image, using
resize()
on the image causes it to be rotated 90 degrees.The problem replicates with a mere
sharp('./bugged-in.jpg').resize(300).toFile('./bugged-out.jpg')
.Reading out the file metadata, for the bugged file we get:
To confirm that the issue lies with the orientation field, I took the same image, rotated it 90 degrees left in the macOS Preview app, saved it, rotated it 90 degrees to the right, and saved it again to normalize the orientation.
For the working file, we get:
What is the expected behaviour?
Resizing the image should either respect the orientation and/or the orientation should be normalized so the image is not rotated when it's resized.
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem
The issue replicates with
sharp('./bugged-in.jpg').resize(300).toFile('./bugged-out.jpg')
.For your convenience, I've also made a small repo which is a self contained replication of the bug: https://github.com/Etheryte/sharp-demo
Please provide sample image(s) that help explain this problem
Bugged image: https://github.com/Etheryte/sharp-demo/blob/master/bugged-in.jpg
Working image: https://github.com/Etheryte/sharp-demo/blob/master/working-in.jpg
The text was updated successfully, but these errors were encountered: