From eb51d2f0181e959dcaf15218cbbf4342b2e1eb68 Mon Sep 17 00:00:00 2001 From: Mike Pol Date: Mon, 7 Dec 2015 13:24:31 +0300 Subject: [PATCH 1/4] fix svg xml parse --- imagemagick.js | 57 +++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/imagemagick.js b/imagemagick.js index b846c0c..7deb67d 100644 --- a/imagemagick.js +++ b/imagemagick.js @@ -95,7 +95,7 @@ function exec2(file, args /*, options, callback */) { }); return child; -}; +} function parseIdentify(input) { @@ -104,32 +104,44 @@ function parseIdentify(input) { props = [prop], prevIndent = 0, indents = [indent], - currentLine, comps, indent, i; - + currentLine, comps, indent, i, svg, svgText; 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() + + if (currentLine.match(/<\?xml/)) { + svg = true; + svgText = currentLine; + } + + if (svg) { + svgText += currentLine; + } else { + 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; } - prevIndent = indent; + } + if (currentLine.match(/<\/svg>/)) { + svg = false; + prop['svg'] = svgText; } } return prop; -}; +} exports.identify = function(pathOrArgs, callback) { var isCustom = Array.isArray(pathOrArgs), @@ -155,7 +167,7 @@ exports.identify = function(pathOrArgs, callback) { result = parseIdentify(stdout); geometry = result['geometry'].split(/x/); - result.format = result.format.match(/\S*/)[0] + result.format = result.format.match(/\S*/)[0]; result.width = parseInt(geometry[0]); result.height = parseInt(geometry[1]); result.depth = parseInt(result.depth); @@ -174,7 +186,8 @@ exports.identify = function(pathOrArgs, callback) { } } return proc; -} +}; + exports.identify.path = 'identify'; function ExifDate(value) { @@ -280,7 +293,7 @@ exports.crop = function (options, callback) { throw new TypeError("No srcPath or data defined"); if (!options.height && !options.width) throw new TypeError("No width or height defined"); - + if (options.srcPath){ var args = options.srcPath; } else { From 2e3dc51ca0ff26105efc47b116f960b5aa4ad343 Mon Sep 17 00:00:00 2001 From: ilyabrower Date: Fri, 15 Jul 2016 16:06:57 +0300 Subject: [PATCH 2/4] fix identify parser --- imagemagick.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/imagemagick.js b/imagemagick.js index 7deb67d..1041518 100644 --- a/imagemagick.js +++ b/imagemagick.js @@ -103,8 +103,9 @@ function parseIdentify(input) { prop = {}, props = [prop], prevIndent = 0, + ident = 0, indents = [indent], - currentLine, comps, indent, i, svg, svgText; + currentLine, comps, svg, svgText; lines.shift(); //drop first line (Image: name.jpg) for (i in lines) { currentLine = lines[i]; @@ -118,21 +119,23 @@ function parseIdentify(input) { if (svg) { svgText += currentLine; } else { - if (indent >= 0) { + if (currentLine.length > 0) { comps = currentLine.split(': '); - if (indent > prevIndent) indents.push(indent); - while (indent < prevIndent && props.length) { + indent = currentLine.search(/\S/); + while (indent <= prevIndent) { indents.pop(); prop = props.pop(); prevIndent = indents[indents.length - 1]; } + if (comps.length < 2) { + indents.push(indent); props.push(prop); prop = prop[currentLine.split(':')[0].trim().toLowerCase()] = {}; + prevIndent = indent; } else { prop[comps[0].trim().toLowerCase()] = comps[1].trim() } - prevIndent = indent; } } if (currentLine.match(/<\/svg>/)) { @@ -140,7 +143,7 @@ function parseIdentify(input) { prop['svg'] = svgText; } } - return prop; + return props[0]; } exports.identify = function(pathOrArgs, callback) { From c8201b570b67700323e085b5fcd626ed44b3304f Mon Sep 17 00:00:00 2001 From: ilyabrower Date: Mon, 18 Jul 2016 09:34:06 +0300 Subject: [PATCH 3/4] fix identify parser - iNdent --- imagemagick.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imagemagick.js b/imagemagick.js index 1041518..3d7c1de 100644 --- a/imagemagick.js +++ b/imagemagick.js @@ -103,7 +103,7 @@ function parseIdentify(input) { prop = {}, props = [prop], prevIndent = 0, - ident = 0, + indent = 0, indents = [indent], currentLine, comps, svg, svgText; lines.shift(); //drop first line (Image: name.jpg) From cb5bc0313974ec1e2c88bb7fdf01b2258b67cec6 Mon Sep 17 00:00:00 2001 From: Mikhail Poluboyarinov Date: Thu, 8 Jun 2017 10:16:51 +0300 Subject: [PATCH 4/4] update version, update npm scope --- README.md | 4 ++-- package.json | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 32ab110..8ce6006 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,14 @@ You can install this module using [npm](http://github.com/isaacs/npm): - npm install imagemagick + npm install @mikepol/imagemagick Requires imagemagick CLI tools to be installed. There are numerous ways to install them. For instance, if you're on OS X you can use [Homebrew](http://mxcl.github.com/homebrew/): `brew install imagemagick`. ## Example ```javascript -var im = require('imagemagick'); +var im = require('@mikepol/imagemagick'); im.readMetadata('kittens.jpg', function(err, metadata){ if (err) throw err; console.log('Shot at '+metadata.exif.dateTimeOriginal); diff --git a/package.json b/package.json index dfcb83b..e96a4c6 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ -{ "name" : "imagemagick" +{ "name" : "@mikepol/imagemagick" , "description" : "A wrapper around the imagemagick cli" -, "version" : "0.1.3" +, "version" : "0.1.4" , "author" : "Rasmus Andersson " , "licenses" : ["MIT"] , "repository" : { "type" : "git" - , "url" : "http://github.com/rsms/node-imagemagick.git" } + , "url" : "http://github.com/sotadev/node-imagemagick.git" } , "engine" : ["node >=0.6"] , "main" : "imagemagick" }