Read EXIF data?
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?
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); })
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);
});
Is there any way to read Caption[2,120] data directly form a gm object?