| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064 | /** * Dependencies */var argsToArray = require('./utils').argsToArray;/** * Extend proto */module.exports = function (proto) {  // change the specified frame.  // See #202.  proto.selectFrame = function (frame) {    if (typeof frame === 'number')      this.sourceFrames = '[' + frame + ']';    return this;  }  // define the sub-command to use, http://www.graphicsmagick.org/utilities.html  proto.command = proto.subCommand = function subCommand (name){    this._subCommand = name;    return this;  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-adjoin  proto.adjoin = function adjoin () {    return this.out("-adjoin");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-affine  proto.affine = function affine (matrix) {    return this.out("-affine", matrix);  }  /**   * Appends images to the list of "source" images.   *   * We may also specify either top-to-bottom or left-to-right   * behavior of the appending by passing a boolean argument.   *   * Examples:   *   *    img = gm(src);   *   *    // +append means left-to-right   *    img.append(img1, img2)       gm convert src img1 img2 -append   *    img.append(img, true)        gm convert src img +append   *    img.append(img, false)       gm convert src img -append   *    img.append(img)              gm convert src img -append   *    img.append(img).append()     gm convert src img -append   *    img.append(img).append(true) gm convert src img +append   *    img.append(img).append(true) gm convert src img +append   *    img.append(img).background('#222) gm convert src img -background #222 +append   *   * @param {String} [img]   * @param {Boolean} [ltr]   * @see http://www.graphicsmagick.org/GraphicsMagick.html#details-append   */  proto.append = function append (img, ltr) {    if (!this._append) {      this._append = [];      this.addSrcFormatter(function (src) {        this.out(this._append.ltr ? '+append' : '-append');        src.push.apply(src, this._append);      });    }    if (0 === arguments.length) {      this._append.ltr = false;      return this;    }    for (var i = 0; i < arguments.length; ++i) {      var arg = arguments[i];      switch (typeof arg) {        case 'boolean':          this._append.ltr = arg;          break;        case 'string':          this._append.push(arg);          break;      }    }    return this;  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-authenticate  proto.authenticate = function authenticate (string) {    return this.out("-authenticate", string);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-average  proto.average = function average () {    return this.out("-average");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-backdrop  proto.backdrop = function backdrop () {    return this.out("-backdrop");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-black-threshold  proto.blackThreshold = function blackThreshold (red, green, blue, opacity) {    return this.out("-black-threshold", argsToArray(red, green, blue, opacity).join(','));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-blue-primary  proto.bluePrimary = function bluePrimary (x, y) {    return this.out("-blue-primary", argsToArray(x, y).join(','));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-border  proto.border = function border (width, height) {    return this.out("-border", width+"x"+height);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-bordercolor  proto.borderColor = function borderColor (color) {    return this.out("-bordercolor", color);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-box  proto.box = function box (color) {    return this.out("-box", color);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-channel  proto.channel = function channel (type) {    return this.out("-channel", type);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-chop  proto.chop = function chop (w, h, x, y) {    return this.in("-chop", w+"x"+h + "+"+(x||0)+"+"+(y||0));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-clip  proto.clip = function clip () {    return this.out("-clip");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-coalesce  proto.coalesce = function coalesce () {    return this.out("-coalesce");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-colorize  proto.colorize = function colorize (r, g, b) {    return this.out("-colorize", [r,g,b].join(","));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-colormap  proto.colorMap = function colorMap (type) {    return this.out("-colormap", type);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-compose  proto.compose = function compose (operator) {    return this.out("-compose", operator);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-compress  proto.compress = function compress (type) {    return this.out("-compress", type);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-kernel  proto.convolve = function convolve (kernel) {    return this.out("-convolve", kernel);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-create-directories  proto.createDirectories = function createDirectories () {    return this.out("-create-directories");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-deconstruct  proto.deconstruct = function deconstruct () {    return this.out("-deconstruct");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-define  proto.define = function define (value) {    return this.out("-define", value);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-delay  proto.delay = function delay (value) {    return this.out("-delay", value);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-displace  proto.displace = function displace (horizontalScale, verticalScale) {    return this.out("-displace", horizontalScale+'x'+verticalScale);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-display  proto.display = function display (value) {    return this.out("-display", value);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-dispose  proto.dispose = function dispose (method) {    return this.out("-dispose", method);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-encoding  proto.encoding = function encoding (type) {    return this.out("-encoding", type);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-endian  proto.endian = function endian (type) {    return this.out("-endian", type);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-file  proto.file = function file (filename) {    return this.out("-file", filename);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-flatten  proto.flatten = function flatten () {    return this.out("-flatten");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-foreground  proto.foreground = function foreground (color) {    return this.out("-foreground", color);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-frame  proto.frame = function frame (width, height, outerBevelWidth, innerBevelWidth) {    if(arguments.length==0) return this.out("-frame");    return this.out("-frame", width+'x'+height+'+'+outerBevelWidth+'+'+innerBevelWidth);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-fuzz  proto.fuzz = function fuzz (distance, percent) {    return this.out("-fuzz", distance+(percent?'%':''));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-gaussian  proto.gaussian = function gaussian (radius, sigma) {    return this.out("-gaussian", argsToArray(radius, sigma).join('x'));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-geometry  proto.geometry = function geometry (width, height, arg) {    return this.out("-geometry", width+'x'+height+(arg||''));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-green-primary  proto.greenPrimary = function greenPrimary (x, y) {    return this.out("-green-primary", x+','+y);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-highlight-color  proto.highlightColor = function highlightColor (color) {    return this.out("-highlight-color", color);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-highlight-style  proto.highlightStyle = function highlightStyle (style) {    return this.out("-highlight-style", style);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-iconGeometry  proto.iconGeometry = function iconGeometry (geometry) {    return this.out("-iconGeometry", geometry);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-intent  proto.intent = function intent (type) {    return this.out("-intent", type);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-lat  proto.lat = function lat (width, height, offset, percent) {    return this.out("-lat", width+'x'+height+offset+(percent?'%':''));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-level  proto.level = function level (blackPoint, gamma, whitePoint, percent) {    return this.out("-level", argsToArray(blackPoint, gamma, whitePoint).join(',')+(percent?'%':''));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-list  proto.list = function list (type) {    return this.out("-list", type);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-log  proto.log = function log (string) {    return this.out("-log", string);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-loop  proto.loop = function loop (iterations) {    return this.out("-loop", iterations);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-map  proto.map = function map (filename) {    return this.out("-map", filename);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-mask  proto.mask = function mask (filename) {    return this.out("-mask", filename);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-matte  proto.matte = function matte () {    return this.out("-matte");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-mattecolor  proto.matteColor = function matteColor (color) {    return this.out("-mattecolor", color);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-maximum-error  proto.maximumError = function maximumError (limit) {    return this.out("-maximum-error", limit);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-mode  proto.mode = function mode (value) {    return this.out("-mode", value);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-monitor  proto.monitor = function monitor () {    return this.out("-monitor");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-mosaic  proto.mosaic = function mosaic () {    return this.out("-mosaic");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-motion-blur  proto.motionBlur = function motionBlur (radius, sigma, angle) {    var arg=radius;    if (typeof sigma!='undefined') arg+='x'+sigma;    if (typeof angle!='undefined') arg+='+'+angle;    return this.out("-motion-blur", arg);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-name  proto.name = function name () {    return this.out("-name");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-noop  proto.noop = function noop () {    return this.out("-noop");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-normalize  proto.normalize = function normalize () {    return this.out("-normalize");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-opaque  proto.opaque = function opaque (color) {    return this.out("-opaque", color);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-operator  proto.operator = function operator (channel, operator, rvalue, percent) {    return this.out("-operator", channel, operator, rvalue+(percent?'%':''));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-ordered-dither  proto.orderedDither = function orderedDither (channeltype, NxN) {    return this.out("-ordered-dither", channeltype, NxN);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-output-directory  proto.outputDirectory = function outputDirectory (directory) {    return this.out("-output-directory", directory);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-page  proto.page = function page (width, height, arg) {    return this.out("-page", width+'x'+height+(arg||''));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-pause  proto.pause = function pause (seconds) {    return this.out("-pause", seconds);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-pen  proto.pen = function pen (color) {    return this.out("-pen", color);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-ping  proto.ping = function ping () {    return this.out("-ping");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-pointsize  proto.pointSize = function pointSize (value) {    return this.out("-pointsize", value);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-preview  proto.preview = function preview (type) {    return this.out("-preview", type);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-process  proto.process = function process (command) {    return this.out("-process", command);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-profile  proto.profile = function profile (filename) {    return this.out("-profile", filename);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-progress  proto.progress = function progress () {    return this.out("+progress");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-random-threshold  proto.randomThreshold = function randomThreshold (channeltype, LOWxHIGH) {    return this.out("-random-threshold", channeltype, LOWxHIGH);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-recolor  proto.recolor = function recolor (matrix) {    return this.out("-recolor", matrix);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-red-primary  proto.redPrimary = function redPrimary (x, y) {    return this.out("-red-primary", x, y);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-remote  proto.remote = function remote () {    return this.out("-remote");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-render  proto.render = function render () {    return this.out("-render");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-repage  proto.repage = function repage (width, height, xoff, yoff, arg) {    return this.out("-repage", width+'x'+height+'+'+xoff+'+'+yoff+(arg||''));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-sample  proto.sample = function sample (geometry) {    return this.out("-sample", geometry);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-sampling-factor  proto.samplingFactor = function samplingFactor (horizontalFactor, verticalFactor) {    return this.out("-sampling-factor", horizontalFactor+'x'+verticalFactor);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-scene  proto.scene = function scene (value) {    return this.out("-scene", value);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-scenes  proto.scenes = function scenes (start, end) {    return this.out("-scenes", start+'-'+end);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-screen  proto.screen = function screen () {    return this.out("-screen");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-set  proto.set = function set (attribute, value) {    return this.out("-set", attribute, value);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-segment  proto.segment = function segment (clusterThreshold, smoothingThreshold) {    return this.out("-segment", clusterThreshold+'x'+smoothingThreshold);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-shade  proto.shade = function shade (azimuth, elevation) {    return this.out("-shade", azimuth+'x'+elevation);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-shadow  proto.shadow = function shadow (radius, sigma) {    return this.out("-shadow", argsToArray(radius, sigma).join('x'));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-shared-memory  proto.sharedMemory = function sharedMemory () {    return this.out("-shared-memory");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-shave  proto.shave = function shave (width, height, percent) {    return this.out("-shave", width+'x'+height+(percent?'%':''));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-shear  proto.shear = function shear (xDegrees, yDegreees) {    return this.out("-shear", xDegrees+'x'+yDegreees);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-silent  proto.silent = function silent (color) {    return this.out("-silent");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-size  proto.rawSize = function rawSize (width, height, offset) {    var off = 'undefined' != typeof offset      ? '+' + offset      : '';    return this.out("-size", width +'x'+ height + off);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-snaps  proto.snaps = function snaps (value) {    return this.out("-snaps", value);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-stegano  proto.stegano = function stegano (offset) {    return this.out("-stegano", offset);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-stereo  proto.stereo = function stereo () {    return this.out("-stereo");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-text-font  proto.textFont = function textFont (name) {    return this.out("-text-font", name);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-texture  proto.texture = function texture (filename) {    return this.out("-texture", filename);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-threshold  proto.threshold = function threshold (value, percent) {    return this.out("-threshold", value+(percent?'%':''));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-thumbnail  proto.thumbnail = function thumbnail (width, height) {    return this.out("-thumbnail", width + "x" + height);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-tile  proto.tile = function tile (filename) {    return this.out("-tile", filename);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-title  proto.title = function title (string) {    return this.out("-title", string);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-transform  proto.transform = function transform (color) {    return this.out("-transform", color);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-transparent  proto.transparent = function transparent (color) {    return this.out("-transparent", color);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-treedepth  proto.treeDepth = function treeDepth (value) {    return this.out("-treedepth", value);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-update  proto.update = function update (seconds) {    return this.out("-update", seconds);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-units  proto.units = function units (type) {    return this.out("-units", type);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-unsharp  proto.unsharp = function unsharp (radius, sigma, amount, threshold) {    var arg=radius;    if (typeof sigma != 'undefined') arg+='x'+sigma;    if (typeof amount != 'undefined') arg+='+'+amount;    if (typeof threshold != 'undefined') arg+='+'+threshold;    return this.out("-unsharp", arg);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-use-pixmap  proto.usePixmap = function usePixmap () {    return this.out("-use-pixmap");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-view  proto.view = function view (string) {    return this.out("-view", string);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-virtual-pixel  proto.virtualPixel = function virtualPixel (method) {    return this.out("-virtual-pixel", method);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-visual  proto.visual = function visual (type) {    return this.out("-visual", type);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-watermark  proto.watermark = function watermark (brightness, saturation) {    return this.out("-watermark", brightness+'x'+saturation);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-wave  proto.wave = function wave (amplitude, wavelength) {    return this.out("-wave", amplitude+'x'+wavelength);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-white-point  proto.whitePoint = function whitePoint (x, y) {    return this.out("-white-point", x+'x'+y);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-white-threshold  proto.whiteThreshold = function whiteThreshold (red, green, blue, opacity) {    return this.out("-white-threshold", argsToArray(red, green, blue, opacity).join(','));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-window  proto.window = function window (id) {    return this.out("-window", id);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-window-group  proto.windowGroup = function windowGroup () {    return this.out("-window-group");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-strip (graphicsMagick >= 1.3.15)  proto.strip = function strip () {    if (this._options.imageMagick) return this.out("-strip");    return this.noProfile().out("+comment");//Equivalent to "-strip" for all versions of graphicsMagick  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-interlace  proto.interlace = function interlace (type) {    return this.out("-interlace", type || "None");  }  // force output format  proto.setFormat = function setFormat (format) {    if (format) this._outputFormat = format;    return this;  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-resize  proto.resize = function resize (w, h, options) {    options = options || "";    var geometry;    if (w && h) {      geometry = w + "x" + h + options    } else if (w && !h) {      // GraphicsMagick requires <width>x<options>, ImageMagick requires <width><options>      geometry = (this._options.imageMagick) ? w + options : w + 'x' + options;    } else if (!w && h) {      geometry = 'x' + h + options    }    return this.out("-resize", geometry);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-scale  proto.scale = function scale (w, h, options) {    options = options || "";    var geometry;    if (w && h) {      geometry = w + "x" + h + options    } else if (w && !h) {      geometry = (this._options.imageMagick) ? w + options : w + 'x' + options;    } else if (!w && h) {      geometry = 'x' + h + options    }    return this.out("-scale", geometry);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-filter  proto.filter = function filter (val) {    return this.out("-filter", val);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-density  proto.density = function density (w, h) {    return this.in("-density", w +"x"+ h);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-profile  proto.noProfile = function noProfile () {    this.out('+profile', '"*"');    return this;  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-resample  proto.resample = function resample (w, h) {    return this.out("-resample", w+"x"+h);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-rotate  proto.rotate = function rotate (color, deg) {    return this.out("-background", color, "-rotate", String(deg || 0));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-flip  proto.flip = function flip () {    return this.out("-flip");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-flop  proto.flop = function flop () {    return this.out("-flop");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-crop  proto.crop = function crop (w, h, x, y, percent) {    if (this.inputIs('jpg')) {      // avoid error "geometry does not contain image (unable to crop image)" - gh-17      var index = this._in.indexOf('-size');      if (~index) {        this._in.splice(index, 2);      }    }    return this.out("-crop", w + "x" + h + "+" + (x || 0) + "+" + (y || 0) + (percent ? '%' : ''));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-magnify  proto.magnify = function magnify (factor) {    return this.in("-magnify");  }  // http://www.graphicsmagick.org/GraphicsMagick.html  proto.minify = function minify () {    return this.in("-minify")  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-quality  proto.quality = function quality (val) {    return this.in("-quality", val || 75);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-blur  proto.blur = function blur (radius, sigma) {    return this.out("-blur", radius + (sigma ? "x"+sigma : ""));  }  // http://www.graphicsmagick.org/convert.html  proto.charcoal = function charcoal (factor) {    return this.out("-charcoal", factor || 2);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-modulate  proto.modulate = function modulate (b, s, h) {    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.out("+antialias")      : this;  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-depth  proto.bitdepth = function bitdepth (val) {    return this.out("-depth", val);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-colors  proto.colors = function colors (val) {    return this.out("-colors", val || 128);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-colorspace  proto.colorspace = function colorspace (val) {    return this.out("-colorspace", val);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-comment  proto.comment = comment("-comment");  // http://www.graphicsmagick.org/GraphicsMagick.html#details-contrast  proto.contrast = function contrast (mult) {    var arg = (parseInt(mult, 10) || 0) > 0      ? "+contrast"      : "-contrast";    mult = Math.abs(mult) || 1;    while (mult--) {      this.out(arg);    }    return this;  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-cycle  proto.cycle = function cycle (amount) {    return this.out("-cycle", amount || 2);  }  // http://www.graphicsmagick.org/GraphicsMagick.html  proto.despeckle = function despeckle () {    return this.out("-despeckle");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-dither  // note: either colors() or monochrome() must be used for this  // to take effect.  proto.dither = function dither (on) {    var sign = false === on      ? "+"      : "-";    return this.out(sign + "dither");  }  // http://www.graphicsmagick.org/GraphicsMagick.html  proto.monochrome = function monochrome () {    return this.out("-monochrome");  }  // http://www.graphicsmagick.org/GraphicsMagick.html  proto.edge = function edge (radius) {    return this.out("-edge", radius || 1);  }  // http://www.graphicsmagick.org/GraphicsMagick.html  proto.emboss = function emboss (radius) {    return this.out("-emboss", radius || 1);  }  // http://www.graphicsmagick.org/GraphicsMagick.html  proto.enhance = function enhance () {    return this.out("-enhance");  }  // http://www.graphicsmagick.org/GraphicsMagick.html  proto.equalize = function equalize () {    return this.out("-equalize");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-gamma  proto.gamma = function gamma (r, g, b) {    return this.out("-gamma", [r,g,b].join());  }  // http://www.graphicsmagick.org/GraphicsMagick.html  proto.implode = function implode (factor) {    return this.out("-implode", factor || 1);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-comment  proto.label = comment("-label");  var limits = [ "disk", "file", "map", "memory", "pixels", "threads"];  // http://www.graphicsmagick.org/GraphicsMagick.html#details-limit  proto.limit = function limit (type, val) {    type = type.toLowerCase();    if (!~limits.indexOf(type)) {      return this;    }    return this.out("-limit", type, val);  }  // http://www.graphicsmagick.org/GraphicsMagick.html  proto.median = function median (radius) {    return this.out("-median", radius || 1);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-negate  proto.negative = function negative (grayscale) {    var sign = grayscale ? "+" : "-";    return this.out(sign + "negate");  }  var noises = [      "uniform"    , "gaussian"    , "multiplicative"    , "impulse"    , "laplacian"    , "poisson"  ];  // http://www.graphicsmagick.org/GraphicsMagick.html#details-noise  proto.noise = function noise (radius) {    radius = (String(radius)).toLowerCase();    var sign = ~noises.indexOf(radius)      ? "+"      : "-";    return this.out(sign + "noise", radius);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-paint  proto.paint = function paint (radius) {    return this.out("-paint", radius);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-raise  proto.raise = function raise (w, h) {    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.out("+raise", (w||0)+"x"+(h||0));  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-region  proto.region = function region (w, h, x, y) {    w = w || 0;    h = h || 0;    x = x || 0;    y = y || 0;    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.out("-roll", x+y);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-sharpen  proto.sharpen = function sharpen (radius, sigma) {    sigma = sigma      ? "x" + sigma      : "";    return this.out("-sharpen", radius + sigma);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-solarize  proto.solarize = function solarize (factor) {    return this.out("-solarize", (factor || 1)+"%");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-spread  proto.spread = function spread (amount) {    return this.out("-spread", amount || 5);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-swirl  proto.swirl = function swirl (degrees) {    return this.out("-swirl", degrees || 180);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-type  proto.type = function type (type) {    return this.in("-type", type);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-trim  proto.trim = function trim () {    return this.out("-trim");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-extent  proto.extent = function extent (w, h, options) {    options = options || "";    var geometry;    if (w && h) {      geometry = w + "x" + h + options    } else if (w && !h) {      geometry = (this._options.imageMagick) ? w + options : w + 'x' + options;    } else if (!w && h) {      geometry = 'x' + h + options    }    return this.out("-extent", geometry);  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-gravity  // Be sure to use gravity BEFORE extent  proto.gravity = function gravity (type) {    if (!type || !~gravity.types.indexOf(type)) {      type = "NorthWest"; // Documented default.    }    return this.out("-gravity", type);  }  proto.gravity.types = [      "NorthWest"    , "North"    , "NorthEast"    , "West"    , "Center"    , "East"    , "SouthWest"    , "South"    , "SouthEast"  ];  // http://www.graphicsmagick.org/GraphicsMagick.html#details-flatten  proto.flatten = function flatten () {    return this.out("-flatten");  }  // http://www.graphicsmagick.org/GraphicsMagick.html#details-background  proto.background = function background (color) {    return this.in("-background", color);  }};/** * Generates a handler for comments/labels. */function comment (arg) {  return function (format) {    format = String(format);    format = "@" == format.charAt(0)      ? format.substring(1)      : format;    return this.out(arg, '"' + format + '"');  }}
 |