0

I am developing a webApp where user can upload pictures. I am having problems with some SAMSUNG phones. The problem is that when a picture is taken in landscape mode, it is saved horizontally and the exif(orientation) variable set to 0. If the picture is taken in portrait mode, the picture is still stored in landscape mode but the EXIF(orientation) variable is now set to 6 (corresponding to a rotation of 90 deg).

portrait vs landscape

According to the following discussion, JS Client-Side Exif Orientation: Rotate and Mirror JPEG Images

if the orientation variable is set to 6, the following transformation has to be done

case 6: ctx.transform(0, 1, -1, 0, height, 0); break;

this rotates the image 90 deg, and is of course wrong, because the picture has to stay in portrait mode.

wrong portrait

How can the problem be solved ?

  • Have you tried this [solution](https://stackoverflow.com/a/46814952/283851). It's on the same discussion that you linked but is not the top comment, but it's a modified version based on the top comment, which is able to detect orientation and rotate it based on it. I've used his solution on one of my projects where users uploaded images from their device(through camera). – Caleb Taylor May 17 '20 at 08:15
  • I'm afraid this issue is not solvable. The problem is, that you can easily detect the aspect ratio, and rotate the image to portrait, but it's possible to end up to an image being set upside down. What comes to orientation, EXIF data is not always correct (that's probably why the image was saved in wrong orientation at the first place), additionally, EXIF data is often removed from images when saving them on the server. I've solved this by offering users an orientate button, and user can orientate the image before uploading. – Teemu May 17 '20 at 08:17

0 Answers0