hMatoba / piexifjs

Read and modify exif in client-side or server-side JavaScript.
MIT License
573 stars 118 forks source link

Ios exif is null but work on android with same jpg file #52

Open alainib opened 6 years ago

alainib commented 6 years ago

Hello. I use this lib to read exif from jpg, thanks for the nice work. It work very well on android but not on IOS (tested with iphone 5)

I use the same JPG file with exif inside with same code on android and Ios

the JS code to Test if exif where readed good is :

  const prefixe = "data:image/jpeg;base64,";
  const srcdata = await RNFS.readFile(image.path, "base64");
  var exifObj = piexif.load(prefixe + srcdata); 
  for (var ifd in exifObj) {
     if (ifd == "thumbnail") {
     continue;
     }
     console.log("-" + ifd);
     for (var tag in exifObj[ifd]) {
     console.log("  " + piexif.TAGS[ifd][tag]["name"] + ":" + exifObj[ifd][tag]);
     }
  }
  1. IOS results :

If i log exif from piexifjs this is what i get :

  -0th
     Orientation:1
     ExifTag:38
  -Exif
     ColorSpace:1
     PixelXDimension:2448
     PixelYDimension:3264
  -GPS
  -Interop
  -1st 

If i use react-native-image-crop-picker i get good exif on Android and Ios but i need piexifs because i want to read exif, compress jpg then re write exif

log from react-native-image-crop-picker on Ios

   {Exif}:
      ApertureValue:2.52606882168926
      BrightnessValue:3.343102774521297
      ColorSpace:1
      ComponentsConfiguration:(4) [1, 2, 3, 0]
      DateTimeDigitized:"2018:09:28 10:34:06"
      DateTimeOriginal:"2018:09:28 10:34:06"
      ExifVersion:(3) [2, 2, 1]
      ExposureBiasValue:0
      ExposureMode:0
      ExposureProgram:2
      ExposureTime:0.05
      FNumber:2.4
      Flash:24
      FlashPixVersion:(2) [1, 0]
      FocalLenIn35mmFilm:33
      FocalLength:4.12
      ISOSpeedRatings:[64]
      LensMake:"Apple"
      LensModel:"iPhone 5c back camera 4.12mm f/2.4"
      ... 
  1. Android results with same jpg file with piexif

    -0th Make:Apple Model:iPhone 5c Orientation:1 XResolution:72,1 YResolution:72,1 ResolutionUnit:2 Software:Photos 3.0 DateTime:2018:09:28 10:34:06 ExifTag:198 GPSTag:1010 -Exif ExposureTime:1,20 FNumber:12,5 ExposureProgram:2 ISOSpeedRatings:64 ExifVersion:0221 DateTimeOriginal:2018:09:28 10:34:06 DateTimeDigitized:2018:09:28 10:34:06 FlashpixVersion:0100 ColorSpace:1 PixelXDimension:2448 PixelYDimension:3264 SensingMethod:2
    ExposureMode:0 WhiteBalance:0 FocalLengthIn35mmFilm:33 SceneCaptureType:0 LensSpecification:103,25,103,25,12,5,12,5 LensMake:Apple LensModel:iPhone 5c back camera 4.12mm f/2.4 -GPS GPSLatitudeRef:N GPSLatitude:43,1,39,1,619,100 GPSLongitudeRef:E GPSLongitude:3,1,51,1,4265,100 GPSAltitudeRef:0 GPSAltitude:45,1 GPSTimeStamp:8,1,34,1,4,1 GPSSpeedRef:K GPSSpeed:183,100 GPSImgDirectionRef:T GPSImgDirection:21788,115 GPSDestBearingRef:T GPSDestBearing:21788,115 GPSDateStamp:2018:09:28 GPSHPositioningError:100,1 -Interop -1st

Did you think there is a fix ?

EDIT : this is my "transplante" function

  // RNFS is react-native-fs
  const srcdata = await RNFS.readFile(image.path, "base64");

  var srcexifs = piexif.load(prefixe + srcdata);

  //compress image
  const compressedImage = await ImageResizer.createResizedImage(image.path, 900, 900, "JPEG", 72);

  const compressedImageb64 = await RNFS.readFile(compressedImage.uri, "base64");
  // get exif to write them 
  const _zero = srcexifs["0th"];
  const _first = srcexifs["1st"];
  const _Exif = srcexifs["Exif"];
  const _GPS = srcexifs["GPS"];

  var exifObj = { "0th": _zero, "1st": _first, Exif: _Exif, GPS: _GPS };
  var exifbytes = piexif.dump(exifObj);
  //  write the exif in base64 image
  var bs64Exif = piexif.insert(exifbytes, prefixe + compressedImageb64).substring(prefixe.length);
  // write the file
  await RNFS.writeFile(compressedImage.uri, bs64Exif, "base64");
HarelM commented 5 years ago

I have a similar issue, i think, with version 2.0. when using from web browser it works as expected, but when using this library from cordova as which i think is similar to react native, it fails when using load. I think reverting to 1.4 is my best bet...?