From 75b8f1738e8045ede3935f8dbeb72691a8d62d21 Mon Sep 17 00:00:00 2001 From: SvyatoslavPozhydaev Date: Thu, 27 Apr 2023 10:53:13 +0300 Subject: [PATCH] fix identify for calculated format fix #859 --- lib/getters.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/getters.js b/lib/getters.js index 14bbcf05..479705c0 100755 --- a/lib/getters.js +++ b/lib/getters.js @@ -12,6 +12,12 @@ module.exports = function (gm) { const IDENTIFYING = 1; const IDENTIFIED = 2; + + /** + * calculated formats https://imagemagick.org/script/escape.php + * @type {RegExp} + */ + const CALCULATED_FORMATS = /%k|%@|%#/ /** * Map getter functions to output names. @@ -268,8 +274,11 @@ module.exports = function (gm) { function makeArgs (self, val) { var args = [ 'identify' - , '-ping' ]; + + if (!isFormatCalculated(val.format)) { + args.push('-ping') + } if (val.format) { args.push('-format', val.format); @@ -282,6 +291,14 @@ module.exports = function (gm) { args = args.concat(self.src()); return args; } + + /** + * @param {string|undefined} format + * @returns {boolean} + */ + function isFormatCalculated(format) { + return !format || !!CALCULATED_FORMATS.test(format); + } /** * Map exif orientation codes to orientation names.