Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #49 from jteplitz602/master

Made a few changes so that you don't have to write to file for cropping
  • Loading branch information...
commit 1e88bacc6c67b980960af430542eb5505aa6ebf2 2 parents 4e68d0e + 88fa260
@rsms authored
Showing with 25 additions and 7 deletions.
  1. +25 −7 imagemagick.js
View
32 imagemagick.js
@@ -276,25 +276,43 @@ exports.resize = function(options, callback) {
exports.crop = function (options, callback) {
if (typeof options !== 'object')
throw new TypeError('First argument must be an object');
- if (!options.srcPath)
- throw new TypeError("No srcPath defined");
- if (!options.dstPath)
- throw new TypeError("No dstPath defined");
+ if (!options.srcPath && !options.srcData)
+ 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 {
+ var args = {
+ data: options.srcData
+ };
+ }
- exports.identify(options.srcPath, function(err, meta) {
+ exports.identify(args, function(err, meta) {
if (err) return callback && callback(err);
var t = exports.resizeArgs(options),
ignoreArg = false,
+ printNext = false,
args = [];
t.args.forEach(function (arg) {
+ if (printNext === true){
+ console.log("arg", arg);
+ printNext = false;
+ }
// ignoreArg is set when resize flag was found
if (!ignoreArg && (arg != '-resize'))
args.push(arg);
// found resize flag! ignore the next argument
- if (arg == '-resize')
+ if (arg == '-resize'){
+ console.log("resize arg");
ignoreArg = true;
+ printNext = true;
+ }
+ if (arg === "-crop"){
+ console.log("crop arg");
+ printNext = true;
+ }
// found the argument after the resize flag; ignore it and set crop options
if ((arg != "-resize") && ignoreArg) {
var dSrc = meta.width / meta.height,
@@ -344,7 +362,7 @@ exports.resizeArgs = function(options) {
// normalize options
if (!opt.format) opt.format = 'jpg';
if (!opt.srcPath) {
- opt.srcPath = (opt.srcFormat ? opt.srcFormat +':-' : '-');
+ opt.srcPath = (opt.srcFormat ? opt.srcFormat +':-' : '-'); // stdin
}
if (!opt.dstPath)
opt.dstPath = (opt.format ? opt.format+':-' : '-'); // stdout
Please sign in to comment.
Something went wrong with that request. Please try again.