Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use extern package "imagemagick-identify-parser" #83

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 3 additions & 31 deletions imagemagick.js
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,6 @@
var childproc = require('child_process'), var childproc = require('child_process'),
EventEmitter = require('events').EventEmitter; EventEmitter = require('events').EventEmitter,
imParse = require('imagemagick-identify-parser');




function exec2(file, args /*, options, callback */) { function exec2(file, args /*, options, callback */) {
Expand Down Expand Up @@ -99,36 +100,7 @@ function exec2(file, args /*, options, callback */) {




function parseIdentify(input) { function parseIdentify(input) {
var lines = input.split("\n"), return imParse(input, "lower");
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;
}; };


exports.identify = function(pathOrArgs, callback) { exports.identify = function(pathOrArgs, callback) {
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
, "url" : "http://github.com/rsms/node-imagemagick.git" } , "url" : "http://github.com/rsms/node-imagemagick.git" }
, "engine" : ["node >=0.6"] , "engine" : ["node >=0.6"]
, "main" : "imagemagick" , "main" : "imagemagick"
, "dependencies": {
"imagemagick-identify-parser": ">= 0.0.4"
}
} }