Skip to content
Open
Changes from 1 commit
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
Next Next commit
fix svg xml parse
  • Loading branch information
mike1pol authored and Mikhail Poluboyarinov committed Dec 7, 2015
commit eb51d2f0181e959dcaf15218cbbf4342b2e1eb68
57 changes: 35 additions & 22 deletions imagemagick.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function exec2(file, args /*, options, callback */) {
});

return child;
};
}


function parseIdentify(input) {
Expand All @@ -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),
Expand All @@ -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);
Expand All @@ -174,7 +186,8 @@ exports.identify = function(pathOrArgs, callback) {
}
}
return proc;
}
};

exports.identify.path = 'identify';

function ExifDate(value) {
Expand Down Expand Up @@ -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 {
Expand Down