jimp icon indicating copy to clipboard operation
jimp copied to clipboard

Preserve Exif Data

Open Slyke opened this issue 7 years ago • 6 comments

Expected Behavior

Image is being saved with a horizontal and vertical resolution of 96 dpi, even though the input image is 1 dpi. The Resolution Unit also doesn't appear to be saved.

Current Behavior

Jimp is setting its own values, regardless of the input image. There doesn't appear to be a way to change these settings either.

Failure Information (for bugs)

I would expect the meta data to remain the same when saving an image from an input image, but it doesn't appear so.

Steps to Reproduce

var jimp = require('jimp');
const fs = require('fs');

jimp.read('image.jpg', (err, img1) => {
  if (err) throw err;
  const debugOut = JSON.parse(JSON.stringify(img1));
  debugOut.bitmap.data = [];
  fs.writeFile('data.txt', JSON.stringify(debugOut, null, 4), (err3) => {  
    if (err3) throw err;
  });
  img1.write('OUTPUT.JPG'); 
});

Context

I'm working with equirectangular images and creating a script to stitch images together from a Yi VR camera. It is paramount that the metadata stays intact for the images otherwise they can't be stitched. Images can be manually edited in paint, but I it would go much faster if I can automate it. Jimp seems to be ignoring the metadata for an image, no matter what I set it to:

    img1._exif.XResolution = 1;
    img1._exif.YResolution = 1;
  • Jimp Version: 0.3.5
  • Operating System: Windows 10
  • Node version: 8.9.4

Slyke avatar Aug 20 '18 01:08 Slyke

@Slyke this is probably an issue with https://github.com/eugeneware/jpeg-js. I have an issue open to encode exif data here. The DPI issue seems different though, you might want to open another issue there.

I might try to pursue this on my own, but I don't know how easy it will be to add these features to jpeg-js.

hipstersmoothie avatar Aug 20 '18 02:08 hipstersmoothie

As in the other thread, @patrickhulce suggested to use https://github.com/hMatoba/piexifjs to encode and decode exif data.

Slyke avatar Aug 20 '18 05:08 Slyke

PRs welcome! I'm gonna investigate moving just the bytes over as that seems like it could work well. I'll probably get to it later this week

hipstersmoothie avatar Aug 20 '18 05:08 hipstersmoothie

Not sure how to integrate this smoothly with piexifjs.

I got it working on my own repo, but it involves reading the source image, storing the metadata in memory, then reading in, and writing over the output image's metadata after the file has already been written for saving. I'll see if I can figure out how to optionally inject the source metadata into the output buffer on here.

See: https://github.com/Slyke/Yi-360-Studio-Image-Cutter/blob/master/index.js#L164 and line 104

Slyke avatar Aug 21 '18 04:08 Slyke

Potential insight on exif

@patrickhulce

FYI keeping identical exif data for a JPEG should be fairly straight forward, just keeping the bytes in the APP1 'Exif' marker segment and sticking them back in is much easier than creating an EXIF decoder + encoder

hipstersmoothie avatar Sep 03 '18 03:09 hipstersmoothie

The DPI issue seems different though, you might want to open another issue there.

I am not sure if this helps, (haven't tested this solution and probably won't have time to in a next few days/weeks), but i found a library which may solve this issue. (after converting buffer to blob) https://github.com/shutterstock/changedpi

lgzajac avatar Sep 19 '18 13:09 lgzajac