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/imagemagick.js b/imagemagick.js index b846c0c..3d7c1de 100644 --- a/imagemagick.js +++ b/imagemagick.js @@ -95,7 +95,7 @@ function exec2(file, args /*, options, callback */) { }); return child; -}; +} function parseIdentify(input) { @@ -103,33 +103,48 @@ function parseIdentify(input) { 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 { 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" }