DmcSDK / cordova-plugin-mediaPicker

cordova android ios mediaPicker support selection of multiple image and video gif ✨ cordova android 和 ios 图片视频选择cordova插件,支持多图 视频 gif,ui类似微信
MIT License
139 stars 93 forks source link

Is there a way to apply the correct rotation to the image? #17

Open TDola opened 6 years ago

TDola commented 6 years ago

I tested using an LG Phoenix 2, an image taken in portrait, given to me in landscape. I'm sure the picture was actually landscape, and used exif to rotate, but I need the actual image file rotated. Can this plugin have a way to return paths to tmp files with exif rotations applied to the image instead? Or alternatively, change getMedias() to include exifRotate just like getThumbnail() does? That way I don't need to make 2 calls since I don't need the thumbnail, just the rotation value.

Thanks

DmcSDK commented 6 years ago

Ok, I will add this feature in the near future. getMedias() add exifRotate ,

TDola commented 6 years ago

Thank you

TDola commented 6 years ago

Any updates on this? It's a bit of a show stopper for me not having the ability to fix the rotation of images. I am forced to use the lesser cordova-plugin-camera as a gallery picker until this is fixed. I am eager to implement this plugin instead.

DmcSDK commented 6 years ago

@TDola I have done it before and found some problems with IOS, such as IOS vertical screen photography, the angle is 270 degrees. IOS is a standard with a horizontal screen of 0 degrees, so is this what you want?

TDola commented 6 years ago

So iOS in portrait sets EXIF to 270 degrees? Not even 90?

I haven't tested what happens on iOS currently so I am not certain what it does.

That's probably fine, ultimately I am just going to rotate the image by whatever the getMedias function gives. So if that makes the final picture match what the user saw in their view finder and in the plugin, then that's good. The number of rotations required shouldn't matter.

DmcSDK commented 6 years ago

@TDola IOS EXIF Orientation(Some special) http://cc.cocimg.com/api/uploads/20150603/1433297018793594.png EXIF Orientation value=1(degrees=0) http://cc.cocimg.com/api/uploads/20150603/1433297032400034.png EXIF Orientation value=6 (degrees=270)

TDola commented 6 years ago

@DmcSDK If that's the same degrees getThumbnail returns or if that's how to make a portrait image appear as a portrait, then that's fine.
Thank you

DmcSDK commented 6 years ago

I added a new function that might meet your requirements. MediaPicker.getExifForKey

MediaPicker.getExifForKey(resultMedias[i].path,"Orientation", function(data) { alert(data); }, function(e) { console.log(e) });

TDola commented 6 years ago

That sounds perfect (it'll be a few weeks before I can test it). Do you have a list of options that can be requested and what it returns? Is it like this? https://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html

0x0112 Orientation int16u IFD0 1 = Horizontal (normal) 2 = Mirror horizontal 3 = Rotate 180 4 = Mirror vertical 5 = Mirror horizontal and rotate 270 CW 6 = Rotate 90 CW 7 = Mirror horizontal and rotate 90 CW 8 = Rotate 270 CW 1 = Horizontal (normal) 2 = Mirror horizontal 3 = Rotate 180 4 = Mirror vertical 5 = Mirror horizontal and rotate 270 CW 6 = Rotate 90 CW 7 = Mirror horizontal and rotate 90 CW 8 = Rotate 270 CW
TDola commented 5 years ago

@DmcSDK Got a chance to try this. I took a photo in portrait mode. The phone saved the photo as horizontal. The plugin image preview correctly rotated the image to portrait, however getExifForKey for Orientation returns 0. 0 is not a valid value for this EXIF key.

I was able to cause the same behavior on 2 phones so far, an LG Phoenix 2 running Android 6.0 and a Samsung S4 running Android 5.1

I was able to follow this guide for a javascript plugin to do it. https://stackoverflow.com/questions/23196252/phonegap-cordova-camera-plugin-how-to-get-photos-date-time-stamp/23218295#23218295 And it works, so the data is there.

Pierpaolo01 commented 5 years ago

HI @DmcSDK & @TDola

How do you correctly use the getExifForKey?

This is how I use the mediaPicker plugin, I'm new to Cordova dev and wondering how I could implement this function to fix my rotation issue

function startImagePicker(){

  var resultMedias=[];
  var imgs = document.createElement("IMG");
  var args = {
    'selectMode': 100, //100 images 101 images & vid 102 video
    'maxSelectCount': 20,
    'maxSelectSize': 188743680, //188743680=180M (Optional) only android
  };

  var container = document.getElementById('group_cor_images');

  MediaPicker.getMedias(args, function(medias){
    resultMedias = medias;
    getPictures(medias);
  }, function(e){ console.log(e) });

  function getPictures(medias){
    for(var i = 0; i < medias.length; i++){
      album.addImage(medias[i].uri);
    }
  }
}
TDola commented 5 years ago

HI @DmcSDK & @TDola

How do you correctly use the getExifForKey?

This is how I use the mediaPicker plugin, I'm new to Cordova dev and wondering how I could implement this function to fix my rotation issue

function startImagePicker(){

  var resultMedias=[];
  var imgs = document.createElement("IMG");
  var args = {
    'selectMode': 100, //100 images 101 images & vid 102 video
    'maxSelectCount': 20,
    'maxSelectSize': 188743680, //188743680=180M (Optional) only android
  };

  var container = document.getElementById('group_cor_images');

  MediaPicker.getMedias(args, function(medias){
    resultMedias = medias;
    getPictures(medias);
  }, function(e){ console.log(e) });

  function getPictures(medias){
    for(var i = 0; i < medias.length; i++){
      album.addImage(medias[i].uri);
    }
  }
}

Unfortunately I was unable to solve the problem using this plugin. I had to use https://github.com/exif-js/exif-js then calculate a rotation. I use scanbot for taking pictures so I am able to rotate them using scanbot.

DmcSDK commented 5 years ago

@Pierpaolo01

function startImagePicker(){

  var resultMedias=[];
  var imgs = document.createElement("IMG");
  var args = {
    'selectMode': 100, //100 images 101 images & vid 102 video
    'maxSelectCount': 20,
    'maxSelectSize': 188743680, //188743680=180M (Optional) only android
  };

  var container = document.getElementById('group_cor_images');

  MediaPicker.getMedias(args, function(medias){
    resultMedias = medias;
    getPictures(medias);
  }, function(e){ console.log(e) });

  function getPictures(medias){
    for(var i = 0; i < medias.length; i++){
     // try add this code
      MediaPicker.getExifForKey(medias[i].path,"Orientation", function(data) { alert(data); }, function(e) { console.log(e) });
      album.addImage(medias[i].uri);
    }
  }
}

getExifForKey Just get the angle,Can't solve the rotation problem。

mizanr commented 2 years ago

For iOS We can change on MediaPicker.m

/ pase below code in 3rd line of file /

import "UIImage+CropScaleOrientation.h"

/ paste my code inside imageToSandbox function /

if(imageData != nil) { NSString *filename=[asset valueForKey:@"filename"];

/**My Code Start**/ UIImage* image = nil; image=[UIImage imageWithData:imageData]; image = [image imageCorrectedForCaptureOrientation]; imageData = UIImageJPEGRepresentation(image, 1); /**My Code end **/

if ([filename hasSuffix:@".HEIC"]) { imageData = UIImageJPEGRepresentation([U