Permalink
Browse files

crop and resize method

  • Loading branch information...
1 parent bfe640d commit fb29162263a62b4f387aff65f80dde6f0e4eca0e @quiiver committed Mar 10, 2010
Showing with 38 additions and 5 deletions.
  1. +38 −5 magickal.js
View
43 magickal.js
@@ -1,23 +1,56 @@
(function() {
var sys = require('sys');
+
var Magickal = {}
Magickal.Image = function(input) {
this.input = input;
};
Magickal.Image.prototype = {
- argList : [],
-
- write: function(out, callback) {
- var args = this.argList.concat([this.input, out]);
+ inArgs : [],
+
+ outArgs : [],
+
+ cropResized : function(width, height, gravity) {
+ return this.resize(width, height).crop(width, height)
+ },
+
+ resize : function(width, height) {
+ var wh = width + "x" + height;
+ return this.makeArgs(["-resize", wh]);
+ },
+
+ crop : function(width, height) {
+ var wh = width + "x" + height;
+ return this.makeArgs(["-crop", wh]);
+ },
+
+ makeArgs : function(inargs, outargs) {
+ if (arguments.length == 1) {
+ outargs = inargs;
+ inargs = null;
+ }
+ if (inargs) {
+ this.inArgs = this.inArgs.concat(inargs);
+ }
+ if (outargs) {
+ this.outArgs = this.outArgs.concat(outargs);
+ }
+ return this;
+ },
+
+ write : function(out, callback) {
+ this.inArgs.push(this.input);
+ this.outArgs.push(out);
+ var args = this.inArgs.concat(this.outArgs);
this.__run("convert", args, callback);
},
__run : function (cmd, args, callback) {
args.unshift(cmd);
cmd = "gm";
- sys.puts("running command: " + cmd + args.join(" "));
+ sys.puts("running command: " + cmd + " " + args.join(" "));
var p = process.createChildProcess(cmd, args);
p.addListener("output", callback);
p.addListener("error", this.errorHandler);

0 comments on commit fb29162

Please sign in to comment.