Skip to content
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

JPEG files from Chrome/Safari on iPhone, autoconverted from HEIC has rotation issues #4059

Closed
msageryd opened this issue Apr 9, 2024 · 2 comments
Labels

Comments

@msageryd
Copy link

msageryd commented Apr 9, 2024

I'm uploading files to my server, where Sharp is used for rotating and croping thumbnails. If the upload comes from an iPhone where the following criteria is met, the jpeg gives me rotation trouble.

  • Photo from camera or album
  • Photo in portrait mode

Landscape photos works fine. These seems to be represented by real pixels, i.e. w,h = actual pixels.
Portrait photos has w,h as if it was a landscape image.

Orientation = 6, i.e. "image needs to be rotated 90 degrees".

My question:

  • Should I manually rotate the image before attempting other operations?
  • Or should Sharp handle this automatically?

I'm asking because I don't want to implement the manual rotation if this is implemented in Sharp later on.

Please see the attached jpeg file and the below metadata from this file.

{
   "format": "jpeg",
   "size": 1786289,
   "width": 4032,
   "height": 3024,
   "space": "srgb",
   "channels": 3,
   "depth": "uchar",
   "density": 72,
   "chromaSubsampling": "4:2:0",
   "isProgressive": false,
   "hasProfile": true,
   "hasAlpha": false,
   "orientation": 6,
  ...
}

1be43997-6362-429e-b529-4ed230dca213_original

@lovell
Copy link
Owner

lovell commented Apr 9, 2024

sharp will only rotate pixels if you tell it to.

Use rotate() to auto-orient and remove the EXIF Orientation value or use keepExif() to retain the existing EXIF Orientation value.

@msageryd
Copy link
Author

msageryd commented Apr 9, 2024

Thanks for the information. I'm now rotating manually and it works great.

The odd thing about stated pixels and actual pixels might be worth mentioning in the docs. In my case I discovered the problem due to "bad extract area". I tried to crop the file based on the stated pixels, i.e. landscape. In practice the image was portrait and my crop went outside of the image area. It took a while to understand this, because iPhone only seems to create this discrepancy on portrait images, not landscape.

It would also be useful with some more info in the docs about EXIF orientation numbers. It's easy to find, but it would have saved me some hedache because I initially thought that orientation was the same as rotation, i.e. 6 degrees. But 6 means "rotate 90".

I found the info here: https://blog.praveen.science/crazy-image-exif-orientation-bug-or-feature/

And also.
Thank you soo much for the Sharp library. It's really awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants