hMatoba / piexifjs

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

Some exif data is corrupted after using insert() #19

Closed aidanxyz closed 7 years ago

aidanxyz commented 7 years ago

Thanks for the work,

I want to modify exif orientation, which I'm able to do for most images, but for some images some exif data (like "Make", "Model", "X-resolution", "Y-resolution") gets corrupted or lost.

So I tried to compare exif objects before and after modification on those problematic images, but when I try to get exif object using load() after inserting modified exif, I'm getting this error:

Uncaught 'unpack' error. Mismatch between symbol and string length. 2:0.

If I just take the inserted jpegData and create a blob out of it, some of exif data becomes corrupted:

Before:

screen shot 2017-02-22 at 4 35 25 pm

After:

screen shot 2017-02-22 at 4 35 57 pm

Here is the code that I used:

function modifyOrientation(file) {

  var reader = new FileReader();

  reader.onload = function(e) {

    var origDataUrl = e.target.result;
    var exif = piexif.load(origDataUrl);
    console.log(exif);

    exif['0th'][piexif.ImageIFD.Orientation] = 1; // modifying orientation
    var dump = piexif.dump(exif);
    var inserted = piexif.insert(dump, origDataUrl);

    var modifiedExif = piexif.load(inserted); // <== error thrown here
    console.log(modifiedExif);

    debugger;
  };

  reader.readAsDataURL(file);
}

and here is the sample image:

sample 2 - this night scene has sacrificed light for detail and contains no colour

hMatoba commented 7 years ago

Thank you. Fixed it.

aidanxyz commented 7 years ago

Great, when are you going to publish 1.0.3 release?

hMatoba commented 7 years ago

Done : )