terikon / cordova-plugin-photo-library

Maintainer needed. Please contact if you're using this library in your project
MIT License
149 stars 295 forks source link

[Android] Orientation of images is incorrect when using 16:9 aspect ratio in options #9

Closed endoplasmic closed 7 years ago

endoplasmic commented 7 years ago

The thumbnails that are returned are being rotated 90 degrees counter-clockwise, but cropped correctly.

Here is a snip of code that is producing the error:


  const photoLibrary = window.cordova.plugins.photoLibrary;
  photoLibrary.getLibrary(
    items => {
      // do stuff
    },
    error => {
      console.log('Error loading library:', error);
    },
    {
      thumbnailWidth: 924,
      thumbnailHeight: 520,
      quality: 0.8,
    }
  );
viskin commented 7 years ago

Checking this...

viskin commented 7 years ago

I saw 226026d41a7eb169edafeaefaeaf0892c002bb62 in your PR #12. You added orientation value to library item. I wonder how orientation value can be used in JavaScript? I'd prefer that photos just appear in correct orientation as I ask for them, and if it will work, is there any value in orientation field for the app? I think making user of the library know about orientation complicates things, the library should take care of orientation by itself.

viskin commented 7 years ago

I tried values you provided on different photos taken in different orientation on my device (nexus 5x), thumbnails appear right. Can you please send a photo that appears rotated to my email, so I will try to debug it.

endoplasmic commented 7 years ago

Sent to your e-mail and also attaching here. Tested on Note 5, S6 Edge+, S7 Edge.

20161111_095127

edit: interesting, it's showing rotated here as well in GitHub.

viskin commented 7 years ago

Yeah, the photo definitely has interesting property inside that causes rotation. I'll check it tomorrow.

viskin commented 7 years ago

Wow, orientation issue is total mess. Here's article I found about the issue: http://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/ And this repo contains test images of all possible orientations: https://github.com/recurser/exif-orientation-examples

viskin commented 7 years ago

browser platform of photo-library displays images incorrectly because browsers display them incorrectly. I use it only for development, so I don't feel correcting the issue for browser makes sense. Most of sites, including github, have this issue. iOS looks free of this issue, so only platform to fix is android.

viskin commented 7 years ago

Oh man, rotation and EXIF is so hardly broken on android that fixing this bug ended up in project of itself. For example, MediaStore.Images.ImageColumns.ORIENTATION returns incorrect rotation for some images. Happily, ExifInterface always works. I published version 1.1.8, please try it on your file. I checked it with all images of https://github.com/recurser/exif-orientation-examples, and it looks fine.

endoplasmic commented 7 years ago

I will give this a whirl later on. But thanks for looking into this. I'm replying on my iOS device and my attached photo looks fine. Go figure.

viskin commented 7 years ago

Closing it after checking on device.

endoplasmic commented 7 years ago

The rotation portion is working great now, but it's ignoring the image itself and putting black bars on the sides.

The image I posted is rotated correctly, but I can see the whole image instead of cropping and centering like you do with images that are not rotated.

viskin commented 7 years ago

Ok, I see it. Let me see what can be done...

viskin commented 7 years ago

I use ThumbnailUtils.extractThumbnail method now and it seems to work. Please confirm that this branch solves the black borders problem for you: https://github.com/terikon/cordova-plugin-photo-library.git#fix-rotated-thumbnail

endoplasmic commented 7 years ago

Yup, that did the trick. Nice work!