From 4cd7a6ca5851cc6a62ccc67343679e5c948fa597 Mon Sep 17 00:00:00 2001 From: Florian Sesser Date: Mon, 25 Feb 2013 11:39:06 +0100 Subject: [PATCH 1/2] Use extern package "imagemagick-identify-parser" The imagemagick-identify-parser provides a more robust and legible parser for ImageMagick/GraphicsMagick output. --- imagemagick.js | 34 +++------------------------------- package.json | 3 +++ 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/imagemagick.js b/imagemagick.js index b846c0c..a0eca8e 100644 --- a/imagemagick.js +++ b/imagemagick.js @@ -1,5 +1,6 @@ var childproc = require('child_process'), - EventEmitter = require('events').EventEmitter; + EventEmitter = require('events').EventEmitter, + imParse = require('imagemagick-identify-parser'); function exec2(file, args /*, options, callback */) { @@ -99,36 +100,7 @@ function exec2(file, args /*, options, callback */) { function parseIdentify(input) { - var lines = input.split("\n"), - prop = {}, - props = [prop], - prevIndent = 0, - indents = [indent], - currentLine, comps, indent, i; - - lines.shift(); //drop first line (Image: name.jpg) - - for (i in lines) { - currentLine = lines[i]; - indent = currentLine.search(/\S/); - if (indent >= 0) { - comps = currentLine.split(': '); - if (indent > prevIndent) indents.push(indent); - while (indent < prevIndent && props.length) { - indents.pop(); - prop = props.pop(); - prevIndent = indents[indents.length - 1]; - } - if (comps.length < 2) { - props.push(prop); - prop = prop[currentLine.split(':')[0].trim().toLowerCase()] = {}; - } else { - prop[comps[0].trim().toLowerCase()] = comps[1].trim() - } - prevIndent = indent; - } - } - return prop; + return imParse(input, {lowerCase: true}); }; exports.identify = function(pathOrArgs, callback) { diff --git a/package.json b/package.json index dfcb83b..3f9592d 100644 --- a/package.json +++ b/package.json @@ -7,4 +7,7 @@ , "url" : "http://github.com/rsms/node-imagemagick.git" } , "engine" : ["node >=0.6"] , "main" : "imagemagick" +, "dependencies": { + "imagemagick-identify-parser": ">= 0.0.4" +} } From e39ef4bba7e452ca3e8743d88fcf12cf192964e6 Mon Sep 17 00:00:00 2001 From: Florian Sesser Date: Tue, 19 Mar 2013 15:30:28 +0100 Subject: [PATCH 2/2] Update imagemagick.js Update to comply with API proposed by imagemagick-identify-parser author. --- imagemagick.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imagemagick.js b/imagemagick.js index a0eca8e..a55373a 100644 --- a/imagemagick.js +++ b/imagemagick.js @@ -100,7 +100,7 @@ function exec2(file, args /*, options, callback */) { function parseIdentify(input) { - return imParse(input, {lowerCase: true}); + return imParse(input, "lower"); }; exports.identify = function(pathOrArgs, callback) {