Refactored orientation getter to use faster identify call

master
Leonid Beschastny 9 years ago
parent 1d833f7ea5
commit 6ed5020a15
  1. 27
      lib/getters.js

@ -27,7 +27,7 @@ module.exports = function (gm) {
, 'filesize': { key: 'Filesize', format: '%b' }
, 'size': { key: 'size', format: '%wx%h ', helper: 'Geometry' }
, 'color': { key: 'color', format: '%k', helper: 'Colors' }
, 'orientation': { key: 'Orientation', verbose: true }
, 'orientation': { key: 'Orientation', format: '%[EXIF:Orientation]', helper: 'Orientation' }
, 'res': { key: 'Resolution', verbose: true }
}
@ -270,6 +270,21 @@ module.exports = function (gm) {
return args;
}
/**
* Map exif orientation codes to orientation names.
*/
var orientations = {
'1': 'TopLeft'
, '2': 'TopRight'
, '3': 'BottomRight'
, '4': 'BottomLeft'
, '5': 'LeftTop'
, '6': 'RightTop'
, '7': 'RightBottom'
, '8': 'LeftBottom'
}
/**
* identify -verbose helpers
*/
@ -297,4 +312,14 @@ module.exports = function (gm) {
helper.Colors = function Colors (o, val) {
o.color = parseInt(val, 10);
};
helper.Orientation = function Orientation (o, val) {
if (val in orientations) {
o['Profile-EXIF'] || (o['Profile-EXIF'] = {});
o['Profile-EXIF'].Orientation = val;
o.Orientation = orientations[val];
} else {
o.Orientation = val || 'Unknown';
}
};
}

Loading…
Cancel
Save