use gm.{in,out}

master
Aaron Heckmann 13 years ago
parent 8ad4b4e40c
commit 5dd07c17fc
  1. 5
      index.js
  2. 103
      lib/args.js
  3. 2
      lib/convenience/morph.js
  4. 2
      lib/convenience/thumb.js
  5. 32
      lib/drawing.js

@ -31,13 +31,12 @@ function gm (source, height, color) {
width = source;
source = "";
var arg = ["-size", width + "x" + height];
this.in("-size", width + "x" + height);
if (color) {
arg = arg.concat(['"xc:'+ color + '"']);
this.in("xc:"+ color);
}
this.arg(arg);
} else {
source = escape(source);
}

@ -7,105 +7,107 @@ module.exports = function (proto) {
// http://www.graphicsmagick.org/GraphicsMagick.html#details-resize
proto.resize = function resize (w, h) {
return this.arg(["-size", w +"x"+ h], ["-resize ", w +"x"+ h]);
return this.in("-size", w +"x"+ h).out("-resize", w +"x"+ h);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-scale
proto.scale = function scale (w, h) {
return this.arg(null, ["-scale", w +"x"+ h]);
return this.out("-scale", w +"x"+ h);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-profile
proto.noProfile = function noProfile () {
return this.arg(null, ['+profile "*"']);
// profile has a lame particularity so we don't escape
this._out.push('+profile "*"');
return this;
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-resample
proto.resample = function resample (w, h) {
return this.arg(null, ["-resample", w+"x"+h]);
return this.out("-resample", w+"x"+h);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-rotate
proto.rotate = function rotate (color, deg) {
return this.arg(null, ["-background", color]).arg(null, ["-rotate", deg]);
return this.out("-background", color, "-rotate", deg);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-flip
proto.flip = function flip () {
return this.arg(null, ["-flip"]);
return this.out("-flip");
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-flop
proto.flop = function flop () {
return this.arg(null, ["-flop"]);
return this.out("-flop");
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-crop
proto.crop = function crop (w, h, x, y) {
return this.arg(null, ["-crop", w+"x"+h + "+"+(x||0)+"+"+(y||0)]);
return this.out("-crop", w+"x"+h + "+"+(x||0)+"+"+(y||0));
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-chop
proto.chop = function chop (w, h, x, y) {
return this.arg(["-chop", w+"x"+h + "+"+(x||0)+"+"+(y||0)]);
return this.in("-chop", w+"x"+h + "+"+(x||0)+"+"+(y||0));
}
// http://www.graphicsmagick.org/GraphicsMagick.html
proto.magnify = function magnify (factor) {
return this.arg(["-magnify", factor || 1]);
return this.in("-magnify", factor || 1);
}
// http://www.graphicsmagick.org/GraphicsMagick.html
proto.minify = function minify (factor) {
return this.arg(["-minify", factor || 1]);
return this.in("-minify", factor || 1);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-quality
proto.quality = function quality (val) {
return this.arg(["-quality", val || 75]);
return this.in("-quality", val || 75);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-blur
proto.blur = function blur (radius, sigma) {
return this.arg(null, ["-blur", radius + (sigma ? "x"+sigma : "") ]);
return this.out("-blur", radius + (sigma ? "x"+sigma : ""));
}
// http://www.graphicsmagick.org/convert.html
proto.charcoal = function charcoal (factor) {
return this.arg(null, ["-charcoal", factor || 2]);
return this.out("-charcoal", factor || 2);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-colorize
proto.colorize = function colorize (r, g, b) {
return this.arg(null, ["-colorize", [r,g,b].join(",")]);
return this.out("-colorize", [r,g,b].join(","));
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-modulate
proto.modulate = function modulate (b, s, h) {
return this.arg(null, ["-modulate", [b,s,h].join(",")]);
return this.out("-modulate", [b,s,h].join(","));
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-antialias
// note: antialiasing is enabled by default
proto.antialias = function antialias (disable) {
return false === disable
? this.arg(null, ["+antialias"])
? this.out("+antialias")
: this;
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-depth
proto.bitdepth = function bitdepth (val) {
return this.arg(null, ["-depth", val]);
return this.out("-depth", val);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-colors
proto.colors = function colors (val) {
return this.arg(null, ["-colors", val || 128]);
return this.out("-colors", val || 128);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-colorspace
proto.colorspace = function colorspace (val) {
return this.arg(null, ["-colorspace", val]);
return this.out("-colorspace", val);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-comment
@ -113,28 +115,27 @@ module.exports = function (proto) {
// http://www.graphicsmagick.org/GraphicsMagick.html#details-contrast
proto.contrast = function contrast (mult) {
var args = []
, arg = (parseInt(mult, 10) || 0) > 0
? "+contrast"
: "-contrast";
var arg = (parseInt(mult, 10) || 0) > 0
? "+contrast"
: "-contrast";
mult = Math.abs(mult) || 1;
while (mult--) {
args.push(arg);
this.out(arg);
}
return this.arg(null, args);
return this;
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-cycle
proto.cycle = function cycle (amount) {
return this.arg(null, ["-cycle", amount || 2]);
return this.out("-cycle", amount || 2);
}
// http://www.graphicsmagick.org/GraphicsMagick.html
proto.despeckle = function despeckle () {
return this.arg(null, ["-despeckle"]);
return this.out("-despeckle");
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-dither
@ -145,42 +146,42 @@ module.exports = function (proto) {
? "+"
: "-";
return this.arg(null, [sign + "dither"]);
return this.out(sign + "dither");
}
// http://www.graphicsmagick.org/GraphicsMagick.html
proto.monochrome = function monochrome () {
return this.arg(null, ["-monochrome"]);
return this.out("-monochrome");
}
// http://www.graphicsmagick.org/GraphicsMagick.html
proto.edge = function edge (radius) {
return this.arg(null, ["-edge", radius || 1]);
return this.out("-edge", radius || 1);
}
// http://www.graphicsmagick.org/GraphicsMagick.html
proto.emboss = function emboss (radius) {
return this.arg(null, ["-emboss", radius || 1]);
return this.out("-emboss", radius || 1);
}
// http://www.graphicsmagick.org/GraphicsMagick.html
proto.enhance = function enhance () {
return this.arg(null, ["-enhance"]);
return this.out("-enhance");
}
// http://www.graphicsmagick.org/GraphicsMagick.html
proto.equalize = function equalize () {
return this.arg(null, ["-equalize"]);
return this.out("-equalize");
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-gamma
proto.gamma = function gamma (r, g, b) {
return this.arg(null, ["-gamma", [r,g,b].join()]);
return this.out("-gamma", [r,g,b].join());
}
// http://www.graphicsmagick.org/GraphicsMagick.html
proto.implode = function implode (factor) {
return this.arg(null, ["-implode", factor || 1]);
return this.out("-implode", factor || 1);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-comment
@ -196,18 +197,18 @@ module.exports = function (proto) {
return this;
}
return this.arg(null, ["-limit", type, val]);
return this.out("-limit", type, val);
}
// http://www.graphicsmagick.org/GraphicsMagick.html
proto.median = function median (radius) {
return this.arg(null, ["-median", radius || 1]);
return this.out("-median", radius || 1);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-negate
proto.negative = function negative (grayscale) {
var sign = grayscale ? "+" : "-";
return this.arg(null, [sign + "negate"]);
return this.out(sign + "negate");
}
var noises = [
@ -226,22 +227,22 @@ module.exports = function (proto) {
? "+"
: "-";
return this.arg(null, [sign + "noise", radius]);
return this.out(sign + "noise", radius);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-paint
proto.paint = function paint (radius) {
return this.arg(null, ["-paint", radius]);
return this.out("-paint", radius);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-raise
proto.raise = function raise (w, h) {
return this.arg(null, ["-raise", (w||0)+"x"+(h||0)]);
return this.out("-raise", (w||0)+"x"+(h||0));
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-raise
proto.lower = function lower (w, h) {
return this.arg(null, ["+raise", (w||0)+"x"+(h||0)]);
return this.out("+raise", (w||0)+"x"+(h||0));
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-region
@ -250,14 +251,14 @@ module.exports = function (proto) {
h = h || 0;
x = x || 0;
y = y || 0;
return this.arg(null, ["-region", w + "x" + h + "+" + x + "+" + y]);
return this.out("-region", w + "x" + h + "+" + x + "+" + y);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-roll
proto.roll = function roll (x, y) {
x = ((x = parseInt(x, 10) || 0) > 0 ? "+" : "") + x;
y = ((y = parseInt(y, 10) || 0) > 0 ? "+" : "") + y;
return this.arg(null, ["-roll", x+y]);
return this.out("-roll", x+y);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-sharpen
@ -266,27 +267,27 @@ module.exports = function (proto) {
? "x" + sigma
: "";
return this.arg(null, ["-sharpen", radius + sigma]);
return this.out("-sharpen", radius + sigma);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-solarize
proto.solarize = function solarize (factor) {
return this.arg(null, ["-solarize", (factor || 1)+"%"]);
return this.out("-solarize", (factor || 1)+"%");
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-spread
proto.spread = function spread (amount) {
return this.arg(null, ["-spread", amount || 5]);
return this.out("-spread", amount || 5);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-swirl
proto.swirl = function swirl (degrees) {
return this.arg(null, ["-swirl", degrees || 180]);
return this.out("-swirl", degrees || 180);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-type
proto.type = function type (type) {
return this.arg(["-type", type]);
return this.in("-type", type);
}
};
@ -302,6 +303,6 @@ function comment (arg) {
? format.substring(1)
: format;
return this.arg(null, [arg, '"' + format + '"']);
return this.out(arg, '"' + format + '"');
}
}

@ -17,7 +17,7 @@ proto.morph = function morph (other, outname, callback) {
var self = this;
self.arg(null, [other, "-morph", 1]);
self.out(other, "-morph", 1);
self.write(outname, function (err, stdout, stderr, cmd) {
if (err) {

@ -44,7 +44,7 @@ proto.thumb = function thumb (w, h, name, quality, callback) {
self
.quality(quality)
.arg(["-size", w1+"x"+h1])
.in("-size", w1+"x"+h1)
.scale(w1, h1)
.crop(w, h)
.noProfile()

@ -2,7 +2,7 @@ module.exports = function (proto) {
// http://www.graphicsmagick.org/GraphicsMagick.html#details-fill
proto.fill = function fill (color) {
return this.arg(null, ["-fill", "'" + (color || "none") + "'"]);
return this.out("-fill", color || "none");
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-stroke
@ -11,12 +11,12 @@ module.exports = function (proto) {
this.strokeWidth(width);
}
return this.arg(null, ["-stroke", "'" + (color || "none") + "'"]);
return this.out("-stroke", color || "none");
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-strokewidth
proto.strokeWidth = function strokeWidth (width) {
return this.arg(null, ["-strokewidth", width]);
return this.out("-strokewidth", width);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-font
@ -25,27 +25,27 @@ module.exports = function (proto) {
this.fontSize(size);
}
return this.arg(null, ["-font", font]);
return this.out("-font", font);
}
// http://www.graphicsmagick.org/GraphicsMagick.html
proto.fontSize = function fontSize (size) {
return this.arg(null, ["-pointsize", size]);
return this.out("-pointsize", size);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-draw
proto.draw = function draw (args) {
return this.arg(null, ["-draw", "'"+ args.join(" ") + "'"]);
return this.out("-draw", [].slice.call(arguments).join(" "));
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-draw
proto.drawPoint = function drawPoint (x, y) {
return this.draw(["point", x +","+ y]);
return this.draw("point", x +","+ y);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-draw
proto.drawLine = function drawLine (x0, y0, x1, y1) {
return this.draw(["line", x0+","+y0, x1+","+y1]);
return this.draw("line", x0+","+y0, x1+","+y1);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-draw
@ -63,24 +63,24 @@ module.exports = function (proto) {
lastarg = wc+","+hc;
}
return this.draw([shape, x0+","+y0, x1+","+y1, lastarg]);
return this.draw(shape, x0+","+y0, x1+","+y1, lastarg);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-draw
proto.drawArc = function drawArc (x0, y0, x1, y1, a0, a1) {
return this.draw(["arc", x0+","+y0, x1+","+y1, a0+","+a1]);
return this.draw("arc", x0+","+y0, x1+","+y1, a0+","+a1);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-draw
proto.drawEllipse = function drawEllipse (x0, y0, rx, ry, a0, a1) {
if (a0 == undefined) a0 = 0;
if (a1 == undefined) a1 = 360;
return this.draw(["ellipse", x0+","+y0, rx+","+ry, a0+","+a1]);
return this.draw("ellipse", x0+","+y0, rx+","+ry, a0+","+a1);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-draw
proto.drawCircle = function drawCircle (x0, y0, x1, y1) {
return this.draw(["circle", x0+","+y0, x1+","+y1]);
return this.draw("circle", x0+","+y0, x1+","+y1);
}
// http://www.graphicsmagick.org/GraphicsMagick.html#details-draw
@ -112,13 +112,13 @@ module.exports = function (proto) {
// http://www.graphicsmagick.org/GraphicsMagick.html#details-draw
proto.drawText = function drawText (x0, y0, text, gravity) {
var gravity = String(gravity || "").toLowerCase()
, arg = ["text", x0+","+y0, '"'+text+'"'];
, arg = ["text " + x0 + "," + y0 + ' "' + text + '"'];
if (~this._gravities.indexOf(gravity)) {
arg = ["gravity", gravity].concat(arg);
arg.unshift("gravity", gravity);
}
return this.draw(arg);
return this.draw.apply(this, arg);
}
proto._drawProps = ["color", "matte"];
@ -131,7 +131,7 @@ module.exports = function (proto) {
return this;
}
return this.draw([prop, x+","+y, method]);
return this.draw(prop, x+","+y, method);
}
}

Loading…
Cancel
Save