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

Demo app: Images rotated if added from iOS / macOS photo library #30

Open
robertknight opened this issue May 31, 2022 · 6 comments
Open

Comments

@robertknight
Copy link
Owner

When loading an image into the web demo app directly from the iOS / macOS photo library, the images frequently end up rotated, though they are displayed in the correct orientation in the Photo Library itself. Due to #29, the OCR then doesn't work as expected. If I first export the image to a JPEG by dragging the image from Photos => Finder and then Finder => web app, it works as expected.

If the demo app automatically detected the orientation of the image and rotated it, that would solve the problem.

@robertknight
Copy link
Owner Author

#34 can help by providing a way to detect non-portrait orientation and then providing the user with a way to correct it.

@robertknight
Copy link
Owner Author

Update: This only happens in Safari, so I think it is just another case of the issue where Safari does not respect EXIF orientation information when loading images via createImageBitmap and then drawing them on the canvas. My guess as to why it works when exporting the image from Photos to disk (ie. Photos => Finder => web app) is that during the initial export, the orientation is applied to the actual order of pixels in the image.

See also whatwg/html#7210 (comment).

@robertknight
Copy link
Owner Author

Possibly related WebKit issues:

https://bugs.webkit.org/show_bug.cgi?id=203482 (Orientation not preserved after image resizing)
https://bugs.webkit.org/show_bug.cgi?id=207088 (EXIF metadata lost when using file upload)

I should note that I have the "High efficiency" (HEIF/HEVC) option selected in the Camera Formats settings in iOS.

@robertknight
Copy link
Owner Author

An option for Safari might be to handle reading and applying the EXIF orientation data from the file ourselves, eg. using https://github.com/exif-js/exif-js, this is assuming that the relevant EXIF data is present. The orientation is preserved when dragging from Photos => the NanoJPEG demo app: https://github.com/evanw/skew-nanojpeg, so it looks like it is possible.

@holtwick
Copy link

holtwick commented Jan 28, 2023

I remember that I also had this problem a long time ago. My solution was then based on this code. Maybe it is helpful. But just reading the EXIF data should also do.

https://stackoverflow.com/questions/7584794/accessing-jpeg-exif-rotation-data-in-javascript-on-the-client-side/32490603#32490603

@robertknight
Copy link
Owner Author

Thanks. Those answers suggest it might be possible to read EXIF info with a smaller amount of code than the full EXIF JS. It would be even better if the issue was fixed in WebKit though!

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

No branches or pull requests

2 participants