gm icon indicating copy to clipboard operation
gm copied to clipboard

Read EXIF data?

Open viki53 opened this issue 11 years ago • 3 comments

Not really a bug but an enhancement: is there any way to read EXIF data directly form a gm object?

In fact in my script I allow users to upload a photo so I already have the file's data loaded and a gm version of it to get its dimension. I'd like to read the EXIF data if possible without needing another library (and a third heavy variable).

I didn't find anything in the GraphicsMagick doc about reading exif data so I don't know if it's possible at all. Any suggestion?

viki53 avatar Feb 23 '15 17:02 viki53

Yes you can use formatting string for reading EXIF data. http://www.imagemagick.org/script/escape.php

gm(dir + '/image.jpg').identify('%f %m %c %b', function (err, info) { console.log(info); })

ppbntl19 avatar Jun 09 '15 13:06 ppbntl19

The right format string for Exif data is %[EXIF:*], so an actual code will look something like

gm(dir + '/image.jpg').identify('%[EXIF:*]', function (err, info) {
  // info is a newline separated string of key=value pairs
  // imagemagick also prefixes each line with "exif:"
  var m, exif = {}, re = /^(?:exif:)?(\w+)=(.+)$/mg;
  while (m = re.exec(info)) {
    exif[m[1]] = m[2];
  }
  console.log(exif);
});

lbeschastny avatar Jun 11 '15 07:06 lbeschastny

Is there any way to read Caption[2,120] data directly form a gm object?

rishabh6072 avatar Nov 06 '19 10:11 rishabh6072