Version 0.25.4
Images taken on iOS in portrait orientation get rotated by .resize. It doesn't matter if the image is taken directly from the camera roll or imported from the device or if the image is re-encoded by sending it via text or email. The first two images attached were retrieved with "Image Capture" app and the third was sent via email. The last three images are the output.
What are the steps to reproduce? Load one of the images attached to this bug into a Buffer then
sharp(buf).resize(256, 256).toBuffer(...
Then write that out to a file, then view that file and notice the image was not only resized, it is also rotated 270掳
What is the expected behaviour?
No rotation
What is the output of running npx envinfo --binaries --system?
$ npx envinfo --binaries --system
npx: installed 1 in 1.087s
System:
OS: macOS 10.15.2
CPU: (6) x64 Intel(R) Core(TM) i5-9600K CPU @ 3.70GHz
Memory: 56.79 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.17.0 - /usr/local/bin/node
npm: 6.14.4 - /usr/local/bin/npm
though this happens running on Linux as well.




FWIW, it continues to happen on iOS 14 (pre-release) and MacOS Big Sur (also pre-release).
Hi, the original images will appear to have the "correct" orientation in web browsers and file explorers as these autorotate based on the EXIF orientation metadata they contain, in this example a value of 6.
$ vipsheader -a 87597573-e362df80-c6a6-11ea-8c5d-2795c328771d.JPG | grep Orientation
exif-ifd0-Orientation: 6 (Right-top, Short, 1 components, 2 bytes)
If you'd also like sharp to autorotate the output image based on the input image metadata, use rotate() without parameters.
https://sharp.pixelplumbing.com/api-operation#rotate
If you'd like sharp to maintain the input orientation and save the input metadata to the output metadata, use withMetadata.
馃憦馃徎馃憦馃徎
Thanks. I would argue that withMetadata should be the the default behavior.
Either way, I would vote for a default that provides consistent behavior on multiple platforms. In this case, everything looks correct on the Mac, but not on iOS. Anyways, crisis averted!
Most helpful comment
Hi, the original images will appear to have the "correct" orientation in web browsers and file explorers as these autorotate based on the EXIF orientation metadata they contain, in this example a value of 6.
If you'd also like sharp to autorotate the output image based on the input image metadata, use
rotate()without parameters.https://sharp.pixelplumbing.com/api-operation#rotate
If you'd like sharp to maintain the input orientation and save the input metadata to the output metadata, use
withMetadata.https://sharp.pixelplumbing.com/api-output#withmetadata