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

fix svg xml parse #127

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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);
62 changes: 39 additions & 23 deletions imagemagick.js
Original file line number Diff line number Diff line change
@@ -95,41 +95,56 @@ function exec2(file, args /*, options, callback */) {
});

return child;
};
}


function parseIdentify(input) {
var lines = input.split("\n"),
prop = {},
props = [prop],
prevIndent = 0,
indent = 0,
indents = [indent],
currentLine, comps, indent, i;

currentLine, comps, 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 (currentLine.length > 0) {
comps = currentLine.split(': ');
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>/)) {
svg = false;
prop['svg'] = svgText;
}
}
return prop;
};
return props[0];
}

exports.identify = function(pathOrArgs, callback) {
var isCustom = Array.isArray(pathOrArgs),
@@ -155,7 +170,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 +189,8 @@ exports.identify = function(pathOrArgs, callback) {
}
}
return proc;
}
};

exports.identify.path = 'identify';

function ExifDate(value) {
@@ -280,7 +296,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 {
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <http://rsms.me/>"
, "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"
}