resizing image while saving it's exif orientation with node-gm

2.3k Views Asked by At

I'm writing a nodeJS 5.3.0 application using gm (http://aheckmann.github.io/gm/)

I know that it uses the GraphicsMagicK library.

the problem is that I'm having is that after I resize an image, it loses it's exif format. the code samples actually shows that the exif format is lost.

for example:

var fs = require('fs')
  , gm = require('gm').subClass({imageMagick: true});

// resize and remove EXIF profile data
gm('/path/to/my/img.jpg')
.resize(240, 240)

in this example they say that exif profile data is removed.

I know that I can get the orientation of an image before resizing using:

gm('path/tp/my/img.jpg').orientation(function(err,value){
                var orientation = value;
});

the question is.. can I preserve exif data when resizing ? and If not.. can I set exif orientation data after resizing ?

thanks

1

There are 1 best solutions below

0
Tovo On BEST ANSWER

More specifically in the following code, only noProfile() function remove EXIF, so if you remove it you can preserve EXIF data

 // resize and remove EXIF profile data
gm('/path/to/my/img.jpg')
   .resize(240, 240)
   .noProfile()
   .write('/path/to/resize.png', function (err) {
   if (!err) console.log('done');
});

Otherwise you can check the gm doc here