corrade-nucleus-nucleons – Blame information for rev 36

Subversion Repositories:
Rev:
Rev Author Line No. Line
36 office 1 /**
2 * Dependencies
3 */
4  
5 var argsToArray = require('./utils').argsToArray;
6 var isUtil = require('./utils').isUtil;
7 /**
8 * Extend proto
9 */
10  
11 module.exports = function (proto) {
12 // change the specified frame.
13 // See #202.
14 proto.selectFrame = function (frame) {
15 if (typeof frame === 'number')
16 this.sourceFrames = '[' + frame + ']';
17 return this;
18 }
19  
20 // define the sub-command to use, http://www.graphicsmagick.org/utilities.html
21 proto.command = proto.subCommand = function subCommand (name){
22 this._subCommand = name;
23 return this;
24 }
25  
26 // http://www.graphicsmagick.org/GraphicsMagick.html#details-adjoin
27 proto.adjoin = function adjoin () {
28 return this.out("-adjoin");
29 }
30  
31 // http://www.graphicsmagick.org/GraphicsMagick.html#details-affine
32 proto.affine = function affine (matrix) {
33 return this.out("-affine", matrix);
34 }
35  
36 proto.alpha = function alpha (type) {
37 if (!this._options.imageMagick) return new Error('Method -alpha is not supported by GraphicsMagick');
38 return this.out('-alpha', type);
39 }
40  
41 /**
42 * Appends images to the list of "source" images.
43 *
44 * We may also specify either top-to-bottom or left-to-right
45 * behavior of the appending by passing a boolean argument.
46 *
47 * Examples:
48 *
49 * img = gm(src);
50 *
51 * // +append means left-to-right
52 * img.append(img1, img2) gm convert src img1 img2 -append
53 * img.append(img, true) gm convert src img +append
54 * img.append(img, false) gm convert src img -append
55 * img.append(img) gm convert src img -append
56 * img.append(img).append() gm convert src img -append
57 * img.append(img).append(true) gm convert src img +append
58 * img.append(img).append(true) gm convert src img +append
59 * img.append(img).background('#222) gm convert src img -background #222 +append
60 * img.append([img1,img2...],true)
61  
62 * @param {String} or {Array} [img]
63 * @param {Boolean} [ltr]
64 * @see http://www.graphicsmagick.org/GraphicsMagick.html#details-append
65 */
66  
67 proto.append = function append (img, ltr) {
68 if (!this._append) {
69 this._append = [];
70 this.addSrcFormatter(function (src) {
71 this.out(this._append.ltr ? '+append' : '-append');
72 src.push.apply(src, this._append);
73 });
74 }
75  
76 if (0 === arguments.length) {
77 this._append.ltr = false;
78 return this;
79 }
80  
81 for (var i = 0; i < arguments.length; ++i) {
82 var arg = arguments[i];
83 switch (isUtil(arg)) {
84 case 'Boolean':
85 this._append.ltr = arg;
86 break;
87 case 'String':
88 this._append.push(arg);
89 break;
90 case 'Array':
91 for(var j=0,len=arg.length;j<len;j++){
92 if(isUtil(arg[j]) == 'String'){
93 this._append.push(arg[j]);
94 }
95 }
96 break;
97 }
98 }
99  
100 return this;
101 }
102  
103 // http://www.graphicsmagick.org/GraphicsMagick.html#details-authenticate
104 proto.authenticate = function authenticate (string) {
105 return this.out("-authenticate", string);
106 }
107  
108 // http://www.graphicsmagick.org/GraphicsMagick.html#details-average
109 proto.average = function average () {
110 return this.out("-average");
111 }
112  
113 // http://www.graphicsmagick.org/GraphicsMagick.html#details-backdrop
114 proto.backdrop = function backdrop () {
115 return this.out("-backdrop");
116 }
117  
118 // http://www.graphicsmagick.org/GraphicsMagick.html#details-black-threshold
119 proto.blackThreshold = function blackThreshold (red, green, blue, opacity) {
120 return this.out("-black-threshold", argsToArray(red, green, blue, opacity).join(','));
121 }
122  
123 // http://www.graphicsmagick.org/GraphicsMagick.html#details-blue-primary
124 proto.bluePrimary = function bluePrimary (x, y) {
125 return this.out("-blue-primary", argsToArray(x, y).join(','));
126 }
127  
128 // http://www.graphicsmagick.org/GraphicsMagick.html#details-border
129 proto.border = function border (width, height) {
130 return this.out("-border", width+"x"+height);
131 }
132  
133 // http://www.graphicsmagick.org/GraphicsMagick.html#details-bordercolor
134 proto.borderColor = function borderColor (color) {
135 return this.out("-bordercolor", color);
136 }
137  
138 // http://www.graphicsmagick.org/GraphicsMagick.html#details-box
139 proto.box = function box (color) {
140 return this.out("-box", color);
141 }
142  
143 // http://www.graphicsmagick.org/GraphicsMagick.html#details-channel
144 proto.channel = function channel (type) {
145 return this.out("-channel", type);
146 }
147  
148 // http://www.graphicsmagick.org/GraphicsMagick.html#details-chop
149 proto.chop = function chop (w, h, x, y) {
150 return this.in("-chop", w+"x"+h + "+"+(x||0)+"+"+(y||0));
151 }
152  
153 // http://www.graphicsmagick.org/GraphicsMagick.html#details-clip
154 proto.clip = function clip () {
155 return this.out("-clip");
156 }
157  
158 // http://www.graphicsmagick.org/GraphicsMagick.html#details-coalesce
159 proto.coalesce = function coalesce () {
160 return this.out("-coalesce");
161 }
162  
163 // http://www.graphicsmagick.org/GraphicsMagick.html#details-colorize
164 proto.colorize = function colorize (r, g, b) {
165 return this.out("-colorize", [r,g,b].join(","));
166 }
167  
168 // http://www.graphicsmagick.org/GraphicsMagick.html#details-colormap
169 proto.colorMap = function colorMap (type) {
170 return this.out("-colormap", type);
171 }
172  
173 // http://www.graphicsmagick.org/GraphicsMagick.html#details-compose
174 proto.compose = function compose (operator) {
175 return this.out("-compose", operator);
176 }
177  
178 // http://www.graphicsmagick.org/GraphicsMagick.html#details-compress
179 proto.compress = function compress (type) {
180 return this.out("-compress", type);
181 }
182  
183 // http://www.graphicsmagick.org/GraphicsMagick.html#details-kernel
184 proto.convolve = function convolve (kernel) {
185 return this.out("-convolve", kernel);
186 }
187  
188 // http://www.graphicsmagick.org/GraphicsMagick.html#details-create-directories
189 proto.createDirectories = function createDirectories () {
190 return this.out("-create-directories");
191 }
192  
193 // http://www.graphicsmagick.org/GraphicsMagick.html#details-deconstruct
194 proto.deconstruct = function deconstruct () {
195 return this.out("-deconstruct");
196 }
197  
198 // http://www.graphicsmagick.org/GraphicsMagick.html#details-define
199 proto.define = function define (value) {
200 return this.out("-define", value);
201 }
202  
203 // http://www.graphicsmagick.org/GraphicsMagick.html#details-delay
204 proto.delay = function delay (value) {
205 return this.out("-delay", value);
206 }
207  
208 // http://www.graphicsmagick.org/GraphicsMagick.html#details-displace
209 proto.displace = function displace (horizontalScale, verticalScale) {
210 return this.out("-displace", horizontalScale+'x'+verticalScale);
211 }
212  
213 // http://www.graphicsmagick.org/GraphicsMagick.html#details-display
214 proto.display = function display (value) {
215 return this.out("-display", value);
216 }
217  
218 // http://www.graphicsmagick.org/GraphicsMagick.html#details-dispose
219 proto.dispose = function dispose (method) {
220 return this.out("-dispose", method);
221 }
222  
223 // http://www.graphicsmagick.org/GraphicsMagick.html#details-dissolve
224 proto.dissolve = function dissolve (percent) {
225 return this.out("-dissolve", percent+'%');
226 }
227  
228 // http://www.graphicsmagick.org/GraphicsMagick.html#details-encoding
229 proto.encoding = function encoding (type) {
230 return this.out("-encoding", type);
231 }
232  
233 // http://www.graphicsmagick.org/GraphicsMagick.html#details-endian
234 proto.endian = function endian (type) {
235 return this.out("-endian", type);
236 }
237  
238 // http://www.graphicsmagick.org/GraphicsMagick.html#details-file
239 proto.file = function file (filename) {
240 return this.out("-file", filename);
241 }
242  
243 // http://www.graphicsmagick.org/GraphicsMagick.html#details-flatten
244 proto.flatten = function flatten () {
245 return this.out("-flatten");
246 }
247  
248 // http://www.graphicsmagick.org/GraphicsMagick.html#details-foreground
249 proto.foreground = function foreground (color) {
250 return this.out("-foreground", color);
251 }
252  
253 // http://www.graphicsmagick.org/GraphicsMagick.html#details-frame
254 proto.frame = function frame (width, height, outerBevelWidth, innerBevelWidth) {
255 if(arguments.length==0) return this.out("-frame");
256 return this.out("-frame", width+'x'+height+'+'+outerBevelWidth+'+'+innerBevelWidth);
257 }
258  
259 // http://www.graphicsmagick.org/GraphicsMagick.html#details-fuzz
260 proto.fuzz = function fuzz (distance, percent) {
261 return this.out("-fuzz", distance+(percent?'%':''));
262 }
263  
264 // http://www.graphicsmagick.org/GraphicsMagick.html#details-gaussian
265 proto.gaussian = function gaussian (radius, sigma) {
266 return this.out("-gaussian", argsToArray(radius, sigma).join('x'));
267 }
268  
269 // http://www.graphicsmagick.org/GraphicsMagick.html#details-geometry
270 proto.geometry = function geometry (width, height, arg) {
271 // If the first argument is a string, and there is only one argument, this is a custom geometry command.
272 if(arguments.length == 1 && typeof arguments[0] === "string")
273 return this.out("-geometry", arguments[0]);
274  
275 // Otherwise, return a resizing geometry command with an option alrgument.
276 return this.out("-geometry", width+'x'+height+(arg||''));
277 }
278  
279 // http://www.graphicsmagick.org/GraphicsMagick.html#details-green-primary
280 proto.greenPrimary = function greenPrimary (x, y) {
281 return this.out("-green-primary", x+','+y);
282 }
283  
284 // http://www.graphicsmagick.org/GraphicsMagick.html#details-highlight-color
285 proto.highlightColor = function highlightColor (color) {
286 return this.out("-highlight-color", color);
287 }
288  
289 // http://www.graphicsmagick.org/GraphicsMagick.html#details-highlight-style
290 proto.highlightStyle = function highlightStyle (style) {
291 return this.out("-highlight-style", style);
292 }
293  
294 // http://www.graphicsmagick.org/GraphicsMagick.html#details-iconGeometry
295 proto.iconGeometry = function iconGeometry (geometry) {
296 return this.out("-iconGeometry", geometry);
297 }
298  
299 // http://www.graphicsmagick.org/GraphicsMagick.html#details-intent
300 proto.intent = function intent (type) {
301 return this.out("-intent", type);
302 }
303  
304 // http://www.graphicsmagick.org/GraphicsMagick.html#details-lat
305 proto.lat = function lat (width, height, offset, percent) {
306 return this.out("-lat", width+'x'+height+offset+(percent?'%':''));
307 }
308  
309 // http://www.graphicsmagick.org/GraphicsMagick.html#details-level
310 proto.level = function level (blackPoint, gamma, whitePoint, percent) {
311 return this.out("-level", argsToArray(blackPoint, gamma, whitePoint).join(',')+(percent?'%':''));
312 }
313  
314 // http://www.graphicsmagick.org/GraphicsMagick.html#details-list
315 proto.list = function list (type) {
316 return this.out("-list", type);
317 }
318  
319 // http://www.graphicsmagick.org/GraphicsMagick.html#details-log
320 proto.log = function log (string) {
321 return this.out("-log", string);
322 }
323  
324 // http://www.graphicsmagick.org/GraphicsMagick.html#details-loop
325 proto.loop = function loop (iterations) {
326 return this.out("-loop", iterations);
327 }
328  
329 // http://www.graphicsmagick.org/GraphicsMagick.html#details-map
330 proto.map = function map (filename) {
331 return this.out("-map", filename);
332 }
333  
334 // http://www.graphicsmagick.org/GraphicsMagick.html#details-mask
335 proto.mask = function mask (filename) {
336 return this.out("-mask", filename);
337 }
338  
339 // http://www.graphicsmagick.org/GraphicsMagick.html#details-matte
340 proto.matte = function matte () {
341 return this.out("-matte");
342 }
343  
344 // http://www.graphicsmagick.org/GraphicsMagick.html#details-mattecolor
345 proto.matteColor = function matteColor (color) {
346 return this.out("-mattecolor", color);
347 }
348  
349 // http://www.graphicsmagick.org/GraphicsMagick.html#details-maximum-error
350 proto.maximumError = function maximumError (limit) {
351 return this.out("-maximum-error", limit);
352 }
353  
354 // http://www.graphicsmagick.org/GraphicsMagick.html#details-mode
355 proto.mode = function mode (value) {
356 return this.out("-mode", value);
357 }
358  
359 // http://www.graphicsmagick.org/GraphicsMagick.html#details-monitor
360 proto.monitor = function monitor () {
361 return this.out("-monitor");
362 }
363  
364 // http://www.graphicsmagick.org/GraphicsMagick.html#details-mosaic
365 proto.mosaic = function mosaic () {
366 return this.out("-mosaic");
367 }
368  
369 // http://www.graphicsmagick.org/GraphicsMagick.html#details-motion-blur
370 proto.motionBlur = function motionBlur (radius, sigma, angle) {
371 var arg=radius;
372 if (typeof sigma!='undefined') arg+='x'+sigma;
373 if (typeof angle!='undefined') arg+='+'+angle;
374 return this.out("-motion-blur", arg);
375 }
376  
377 // http://www.graphicsmagick.org/GraphicsMagick.html#details-name
378 proto.name = function name () {
379 return this.out("-name");
380 }
381  
382 // http://www.graphicsmagick.org/GraphicsMagick.html#details-noop
383 proto.noop = function noop () {
384 return this.out("-noop");
385 }
386  
387 // http://www.graphicsmagick.org/GraphicsMagick.html#details-normalize
388 proto.normalize = function normalize () {
389 return this.out("-normalize");
390 }
391  
392 // http://www.graphicsmagick.org/GraphicsMagick.html#details-opaque
393 proto.opaque = function opaque (color) {
394 return this.out("-opaque", color);
395 }
396  
397 // http://www.graphicsmagick.org/GraphicsMagick.html#details-operator
398 proto.operator = function operator (channel, operator, rvalue, percent) {
399 return this.out("-operator", channel, operator, rvalue+(percent?'%':''));
400 }
401  
402 // http://www.graphicsmagick.org/GraphicsMagick.html#details-ordered-dither
403 proto.orderedDither = function orderedDither (channeltype, NxN) {
404 return this.out("-ordered-dither", channeltype, NxN);
405 }
406  
407 // http://www.graphicsmagick.org/GraphicsMagick.html#details-output-directory
408 proto.outputDirectory = function outputDirectory (directory) {
409 return this.out("-output-directory", directory);
410 }
411  
412 // http://www.graphicsmagick.org/GraphicsMagick.html#details-page
413 proto.page = function page (width, height, arg) {
414 return this.out("-page", width+'x'+height+(arg||''));
415 }
416  
417 // http://www.graphicsmagick.org/GraphicsMagick.html#details-pause
418 proto.pause = function pause (seconds) {
419 return this.out("-pause", seconds);
420 }
421  
422 // http://www.graphicsmagick.org/GraphicsMagick.html#details-pen
423 proto.pen = function pen (color) {
424 return this.out("-pen", color);
425 }
426  
427 // http://www.graphicsmagick.org/GraphicsMagick.html#details-ping
428 proto.ping = function ping () {
429 return this.out("-ping");
430 }
431  
432 // http://www.graphicsmagick.org/GraphicsMagick.html#details-pointsize
433 proto.pointSize = function pointSize (value) {
434 return this.out("-pointsize", value);
435 }
436  
437 // http://www.graphicsmagick.org/GraphicsMagick.html#details-preview
438 proto.preview = function preview (type) {
439 return this.out("-preview", type);
440 }
441  
442 // http://www.graphicsmagick.org/GraphicsMagick.html#details-process
443 proto.process = function process (command) {
444 return this.out("-process", command);
445 }
446  
447 // http://www.graphicsmagick.org/GraphicsMagick.html#details-profile
448 proto.profile = function profile (filename) {
449 return this.out("-profile", filename);
450 }
451  
452 // http://www.graphicsmagick.org/GraphicsMagick.html#details-progress
453 proto.progress = function progress () {
454 return this.out("+progress");
455 }
456  
457 // http://www.graphicsmagick.org/GraphicsMagick.html#details-random-threshold
458 proto.randomThreshold = function randomThreshold (channeltype, LOWxHIGH) {
459 return this.out("-random-threshold", channeltype, LOWxHIGH);
460 }
461  
462 // http://www.graphicsmagick.org/GraphicsMagick.html#details-recolor
463 proto.recolor = function recolor (matrix) {
464 return this.out("-recolor", matrix);
465 }
466  
467 // http://www.graphicsmagick.org/GraphicsMagick.html#details-red-primary
468 proto.redPrimary = function redPrimary (x, y) {
469 return this.out("-red-primary", x, y);
470 }
471  
472 // http://www.graphicsmagick.org/GraphicsMagick.html#details-remote
473 proto.remote = function remote () {
474 return this.out("-remote");
475 }
476  
477 // http://www.graphicsmagick.org/GraphicsMagick.html#details-render
478 proto.render = function render () {
479 return this.out("-render");
480 }
481  
482 // http://www.graphicsmagick.org/GraphicsMagick.html#details-repage
483 proto.repage = function repage (width, height, xoff, yoff, arg) {
484 if (arguments[0] === "+") return this.out("+repage");
485 return this.out("-repage", width+'x'+height+'+'+xoff+'+'+yoff+(arg||''));
486 }
487  
488 // http://www.graphicsmagick.org/GraphicsMagick.html#details-sample
489 proto.sample = function sample (geometry) {
490 return this.out("-sample", geometry);
491 }
492  
493 // http://www.graphicsmagick.org/GraphicsMagick.html#details-sampling-factor
494 proto.samplingFactor = function samplingFactor (horizontalFactor, verticalFactor) {
495 return this.out("-sampling-factor", horizontalFactor+'x'+verticalFactor);
496 }
497  
498 // http://www.graphicsmagick.org/GraphicsMagick.html#details-scene
499 proto.scene = function scene (value) {
500 return this.out("-scene", value);
501 }
502  
503 // http://www.graphicsmagick.org/GraphicsMagick.html#details-scenes
504 proto.scenes = function scenes (start, end) {
505 return this.out("-scenes", start+'-'+end);
506 }
507  
508 // http://www.graphicsmagick.org/GraphicsMagick.html#details-screen
509 proto.screen = function screen () {
510 return this.out("-screen");
511 }
512  
513 // http://www.graphicsmagick.org/GraphicsMagick.html#details-set
514 proto.set = function set (attribute, value) {
515 return this.out("-set", attribute, value);
516 }
517  
518 // http://www.graphicsmagick.org/GraphicsMagick.html#details-segment
519 proto.segment = function segment (clusterThreshold, smoothingThreshold) {
520 return this.out("-segment", clusterThreshold+'x'+smoothingThreshold);
521 }
522  
523 // http://www.graphicsmagick.org/GraphicsMagick.html#details-shade
524 proto.shade = function shade (azimuth, elevation) {
525 return this.out("-shade", azimuth+'x'+elevation);
526 }
527  
528 // http://www.graphicsmagick.org/GraphicsMagick.html#details-shadow
529 proto.shadow = function shadow (radius, sigma) {
530 return this.out("-shadow", argsToArray(radius, sigma).join('x'));
531 }
532  
533 // http://www.graphicsmagick.org/GraphicsMagick.html#details-shared-memory
534 proto.sharedMemory = function sharedMemory () {
535 return this.out("-shared-memory");
536 }
537  
538 // http://www.graphicsmagick.org/GraphicsMagick.html#details-shave
539 proto.shave = function shave (width, height, percent) {
540 return this.out("-shave", width+'x'+height+(percent?'%':''));
541 }
542  
543 // http://www.graphicsmagick.org/GraphicsMagick.html#details-shear
544 proto.shear = function shear (xDegrees, yDegreees) {
545 return this.out("-shear", xDegrees+'x'+yDegreees);
546 }
547  
548 // http://www.graphicsmagick.org/GraphicsMagick.html#details-silent
549 proto.silent = function silent (color) {
550 return this.out("-silent");
551 }
552  
553 // http://www.graphicsmagick.org/GraphicsMagick.html#details-size
554 proto.rawSize = function rawSize (width, height, offset) {
555 var off = 'undefined' != typeof offset
556 ? '+' + offset
557 : '';
558 return this.out("-size", width +'x'+ height + off);
559 }
560  
561 // http://www.graphicsmagick.org/GraphicsMagick.html#details-snaps
562 proto.snaps = function snaps (value) {
563 return this.out("-snaps", value);
564 }
565  
566 // http://www.graphicsmagick.org/GraphicsMagick.html#details-stegano
567 proto.stegano = function stegano (offset) {
568 return this.out("-stegano", offset);
569 }
570  
571 // http://www.graphicsmagick.org/GraphicsMagick.html#details-stereo
572 proto.stereo = function stereo () {
573 return this.out("-stereo");
574 }
575  
576 // http://www.graphicsmagick.org/GraphicsMagick.html#details-text-font
577 proto.textFont = function textFont (name) {
578 return this.out("-text-font", name);
579 }
580  
581 // http://www.graphicsmagick.org/GraphicsMagick.html#details-texture
582 proto.texture = function texture (filename) {
583 return this.out("-texture", filename);
584 }
585  
586 // http://www.graphicsmagick.org/GraphicsMagick.html#details-threshold
587 proto.threshold = function threshold (value, percent) {
588 return this.out("-threshold", value+(percent?'%':''));
589 }
590  
591 // http://www.graphicsmagick.org/GraphicsMagick.html#details-thumbnail
592 proto.thumbnail = function thumbnail (w, h, options) {
593 options = options || "";
594 var geometry,
595 wIsValid = Boolean(w || w === 0),
596 hIsValid = Boolean(h || h === 0);
597  
598 if (wIsValid && hIsValid) {
599 geometry = w + "x" + h + options
600 } else if (wIsValid) {
601 // GraphicsMagick requires <width>x<options>, ImageMagick requires <width><options>
602 geometry = (this._options.imageMagick) ? w + options : w +
603 'x' + options;
604 } else if (hIsValid) {
605 geometry = 'x' + h + options
606 } else {
607 return this
608 }
609  
610 return this.out("-thumbnail", geometry);
611 }
612  
613 // http://www.graphicsmagick.org/GraphicsMagick.html#details-tile
614 proto.tile = function tile (filename) {
615 return this.out("-tile", filename);
616 }
617  
618 // http://www.graphicsmagick.org/GraphicsMagick.html#details-title
619 proto.title = function title (string) {
620 return this.out("-title", string);
621 }
622  
623 // http://www.graphicsmagick.org/GraphicsMagick.html#details-transform
624 proto.transform = function transform (color) {
625 return this.out("-transform", color);
626 }
627  
628 // http://www.graphicsmagick.org/GraphicsMagick.html#details-transparent
629 proto.transparent = function transparent (color) {
630 return this.out("-transparent", color);
631 }
632  
633 // http://www.graphicsmagick.org/GraphicsMagick.html#details-treedepth
634 proto.treeDepth = function treeDepth (value) {
635 return this.out("-treedepth", value);
636 }
637  
638 // http://www.graphicsmagick.org/GraphicsMagick.html#details-update
639 proto.update = function update (seconds) {
640 return this.out("-update", seconds);
641 }
642  
643 // http://www.graphicsmagick.org/GraphicsMagick.html#details-units
644 proto.units = function units (type) {
645 return this.out("-units", type);
646 }
647  
648 // http://www.graphicsmagick.org/GraphicsMagick.html#details-unsharp
649 proto.unsharp = function unsharp (radius, sigma, amount, threshold) {
650 var arg=radius;
651 if (typeof sigma != 'undefined') arg+='x'+sigma;
652 if (typeof amount != 'undefined') arg+='+'+amount;
653 if (typeof threshold != 'undefined') arg+='+'+threshold;
654 return this.out("-unsharp", arg);
655 }
656  
657 // http://www.graphicsmagick.org/GraphicsMagick.html#details-use-pixmap
658 proto.usePixmap = function usePixmap () {
659 return this.out("-use-pixmap");
660 }
661  
662 // http://www.graphicsmagick.org/GraphicsMagick.html#details-view
663 proto.view = function view (string) {
664 return this.out("-view", string);
665 }
666  
667 // http://www.graphicsmagick.org/GraphicsMagick.html#details-virtual-pixel
668 proto.virtualPixel = function virtualPixel (method) {
669 return this.out("-virtual-pixel", method);
670 }
671  
672 // http://www.graphicsmagick.org/GraphicsMagick.html#details-visual
673 proto.visual = function visual (type) {
674 return this.out("-visual", type);
675 }
676  
677 // http://www.graphicsmagick.org/GraphicsMagick.html#details-watermark
678 proto.watermark = function watermark (brightness, saturation) {
679 return this.out("-watermark", brightness+'x'+saturation);
680 }
681  
682 // http://www.graphicsmagick.org/GraphicsMagick.html#details-wave
683 proto.wave = function wave (amplitude, wavelength) {
684 return this.out("-wave", amplitude+'x'+wavelength);
685 }
686  
687 // http://www.graphicsmagick.org/GraphicsMagick.html#details-white-point
688 proto.whitePoint = function whitePoint (x, y) {
689 return this.out("-white-point", x+'x'+y);
690 }
691  
692 // http://www.graphicsmagick.org/GraphicsMagick.html#details-white-threshold
693 proto.whiteThreshold = function whiteThreshold (red, green, blue, opacity) {
694 return this.out("-white-threshold", argsToArray(red, green, blue, opacity).join(','));
695 }
696  
697 // http://www.graphicsmagick.org/GraphicsMagick.html#details-window
698 proto.window = function window (id) {
699 return this.out("-window", id);
700 }
701  
702 // http://www.graphicsmagick.org/GraphicsMagick.html#details-window-group
703 proto.windowGroup = function windowGroup () {
704 return this.out("-window-group");
705 }
706  
707 // http://www.graphicsmagick.org/GraphicsMagick.html#details-strip (graphicsMagick >= 1.3.15)
708 proto.strip = function strip () {
709 if (this._options.imageMagick) return this.out("-strip");
710 return this.noProfile().out("+comment");//Equivalent to "-strip" for all versions of graphicsMagick
711 }
712  
713 // http://www.graphicsmagick.org/GraphicsMagick.html#details-interlace
714 proto.interlace = function interlace (type) {
715 return this.out("-interlace", type || "None");
716 }
717  
718 // force output format
719 proto.setFormat = function setFormat (format) {
720 if (format) this._outputFormat = format;
721 return this;
722 }
723  
724 // http://www.graphicsmagick.org/GraphicsMagick.html#details-resize
725 proto.resize = function resize (w, h, options) {
726 options = options || "";
727 var geometry,
728 wIsValid = Boolean(w || w === 0),
729 hIsValid = Boolean(h || h === 0);
730  
731 if (wIsValid && hIsValid) {
732 geometry = w + "x" + h + options
733 } else if (wIsValid) {
734 // GraphicsMagick requires <width>x<options>, ImageMagick requires <width><options>
735 geometry = (this._options.imageMagick) ? w + options : w +
736 'x' + options;
737 } else if (hIsValid) {
738 geometry = 'x' + h + options
739 } else {
740 return this
741 }
742  
743 return this.out("-resize", geometry);
744 }
745  
746 // http://www.graphicsmagick.org/GraphicsMagick.html#details-resize with '!' option
747 proto.resizeExact = function resize (w, h) {
748 var options = "!";
749 return proto.resize.apply(this, [w, h, options]);
750 }
751  
752 // http://www.graphicsmagick.org/GraphicsMagick.html#details-scale
753 proto.scale = function scale (w, h, options) {
754 options = options || "";
755 var geometry;
756 if (w && h) {
757 geometry = w + "x" + h + options
758 } else if (w && !h) {
759 geometry = (this._options.imageMagick) ? w + options : w + 'x' + options;
760 } else if (!w && h) {
761 geometry = 'x' + h + options
762 }
763  
764 return this.out("-scale", geometry);
765 }
766  
767 // http://www.graphicsmagick.org/GraphicsMagick.html#details-filter
768 proto.filter = function filter (val) {
769 return this.out("-filter", val);
770 }
771  
772 // http://www.graphicsmagick.org/GraphicsMagick.html#details-density
773 proto.density = function density (w, h) {
774 if (w && !h && this._options.imageMagick) {
775 // GraphicsMagick requires <width>x<height>y, ImageMagick may take dpi<resolution>
776 // recommended 300dpi for higher quality
777 return this.in("-density", w);
778 }
779 return this.in("-density", w +"x"+ h);
780 }
781  
782 // http://www.graphicsmagick.org/GraphicsMagick.html#details-profile
783 proto.noProfile = function noProfile () {
784 this.out('+profile', '"*"');
785 return this;
786 }
787  
788 // http://www.graphicsmagick.org/GraphicsMagick.html#details-resample
789 proto.resample = function resample (w, h) {
790 return this.out("-resample", w+"x"+h);
791 }
792  
793 // http://www.graphicsmagick.org/GraphicsMagick.html#details-rotate
794 proto.rotate = function rotate (color, deg) {
795 return this.out("-background", color, "-rotate", String(deg || 0));
796 }
797  
798 // http://www.graphicsmagick.org/GraphicsMagick.html#details-flip
799 proto.flip = function flip () {
800 return this.out("-flip");
801 }
802  
803 // http://www.graphicsmagick.org/GraphicsMagick.html#details-flop
804 proto.flop = function flop () {
805 return this.out("-flop");
806 }
807  
808 // http://www.graphicsmagick.org/GraphicsMagick.html#details-crop
809 proto.crop = function crop (w, h, x, y, percent) {
810 if (this.inputIs('jpg')) {
811 // avoid error "geometry does not contain image (unable to crop image)" - gh-17
812 var index = this._in.indexOf('-size');
813 if (~index) {
814 this._in.splice(index, 2);
815 }
816 }
817  
818 return this.out("-crop", w + "x" + h + "+" + (x || 0) + "+" + (y || 0) + (percent ? '%' : ''));
819 }
820  
821 // http://www.graphicsmagick.org/GraphicsMagick.html#details-magnify
822 proto.magnify = function magnify (factor) {
823 return this.in("-magnify");
824 }
825  
826 // http://www.graphicsmagick.org/GraphicsMagick.html
827 proto.minify = function minify () {
828 return this.in("-minify")
829 }
830  
831 // http://www.graphicsmagick.org/GraphicsMagick.html#details-quality
832 proto.quality = function quality (val) {
833 return this.in("-quality", val || 75);
834 }
835  
836 // http://www.graphicsmagick.org/GraphicsMagick.html#details-blur
837 proto.blur = function blur (radius, sigma) {
838 return this.out("-blur", radius + (sigma ? "x"+sigma : ""));
839 }
840  
841 // http://www.graphicsmagick.org/convert.html
842 proto.charcoal = function charcoal (factor) {
843 return this.out("-charcoal", factor || 2);
844 }
845  
846 // http://www.graphicsmagick.org/GraphicsMagick.html#details-modulate
847 proto.modulate = function modulate (b, s, h) {
848 return this.out("-modulate", [b,s,h].join(","));
849 }
850  
851 // http://www.graphicsmagick.org/GraphicsMagick.html#details-antialias
852 // note: antialiasing is enabled by default
853 proto.antialias = function antialias (disable) {
854 return false === disable
855 ? this.out("+antialias")
856 : this;
857 }
858  
859 // http://www.graphicsmagick.org/GraphicsMagick.html#details-depth
860 proto.bitdepth = function bitdepth (val) {
861 return this.out("-depth", val);
862 }
863  
864 // http://www.graphicsmagick.org/GraphicsMagick.html#details-colors
865 proto.colors = function colors (val) {
866 return this.out("-colors", val || 128);
867 }
868  
869 // http://www.graphicsmagick.org/GraphicsMagick.html#details-colorspace
870 proto.colorspace = function colorspace (val) {
871 return this.out("-colorspace", val);
872 }
873  
874 // http://www.graphicsmagick.org/GraphicsMagick.html#details-comment
875 proto.comment = comment("-comment");
876  
877 // http://www.graphicsmagick.org/GraphicsMagick.html#details-contrast
878 proto.contrast = function contrast (mult) {
879 var arg = (parseInt(mult, 10) || 0) > 0
880 ? "+contrast"
881 : "-contrast";
882  
883 mult = Math.abs(mult) || 1;
884  
885 while (mult--) {
886 this.out(arg);
887 }
888  
889 return this;
890 }
891  
892 // http://www.graphicsmagick.org/GraphicsMagick.html#details-cycle
893 proto.cycle = function cycle (amount) {
894 return this.out("-cycle", amount || 2);
895 }
896  
897 // http://www.graphicsmagick.org/GraphicsMagick.html
898 proto.despeckle = function despeckle () {
899 return this.out("-despeckle");
900 }
901  
902 // http://www.graphicsmagick.org/GraphicsMagick.html#details-dither
903 // note: either colors() or monochrome() must be used for this
904 // to take effect.
905 proto.dither = function dither (on) {
906 var sign = false === on
907 ? "+"
908 : "-";
909  
910 return this.out(sign + "dither");
911 }
912  
913 // http://www.graphicsmagick.org/GraphicsMagick.html
914 proto.monochrome = function monochrome () {
915 return this.out("-monochrome");
916 }
917  
918 // http://www.graphicsmagick.org/GraphicsMagick.html
919 proto.edge = function edge (radius) {
920 return this.out("-edge", radius || 1);
921 }
922  
923 // http://www.graphicsmagick.org/GraphicsMagick.html
924 proto.emboss = function emboss (radius) {
925 return this.out("-emboss", radius || 1);
926 }
927  
928 // http://www.graphicsmagick.org/GraphicsMagick.html
929 proto.enhance = function enhance () {
930 return this.out("-enhance");
931 }
932  
933 // http://www.graphicsmagick.org/GraphicsMagick.html
934 proto.equalize = function equalize () {
935 return this.out("-equalize");
936 }
937  
938 // http://www.graphicsmagick.org/GraphicsMagick.html#details-gamma
939 proto.gamma = function gamma (r, g, b) {
940 return this.out("-gamma", [r,g,b].join());
941 }
942  
943 // http://www.graphicsmagick.org/GraphicsMagick.html
944 proto.implode = function implode (factor) {
945 return this.out("-implode", factor || 1);
946 }
947  
948 // http://www.graphicsmagick.org/GraphicsMagick.html#details-comment
949 proto.label = comment("-label");
950  
951 var limits = [ "disk", "file", "map", "memory", "pixels", "threads"];
952  
953 // http://www.graphicsmagick.org/GraphicsMagick.html#details-limit
954 proto.limit = function limit (type, val) {
955 type = type.toLowerCase();
956  
957 if (!~limits.indexOf(type)) {
958 return this;
959 }
960  
961 return this.out("-limit", type, val);
962 }
963  
964 // http://www.graphicsmagick.org/GraphicsMagick.html
965 proto.median = function median (radius) {
966 return this.out("-median", radius || 1);
967 }
968  
969 // http://www.graphicsmagick.org/GraphicsMagick.html#details-negate
970 proto.negative = function negative (grayscale) {
971 var sign = grayscale ? "+" : "-";
972 return this.out(sign + "negate");
973 }
974  
975 var noises = [
976 "uniform"
977 , "gaussian"
978 , "multiplicative"
979 , "impulse"
980 , "laplacian"
981 , "poisson"
982 ];
983  
984 // http://www.graphicsmagick.org/GraphicsMagick.html#details-noise
985 proto.noise = function noise (radius) {
986 radius = (String(radius)).toLowerCase();
987  
988 var sign = ~noises.indexOf(radius)
989 ? "+"
990 : "-";
991  
992 return this.out(sign + "noise", radius);
993 }
994  
995 // http://www.graphicsmagick.org/GraphicsMagick.html#details-paint
996 proto.paint = function paint (radius) {
997 return this.out("-paint", radius);
998 }
999  
1000 // http://www.graphicsmagick.org/GraphicsMagick.html#details-raise
1001 proto.raise = function raise (w, h) {
1002 return this.out("-raise", (w||0)+"x"+(h||0));
1003 }
1004  
1005 // http://www.graphicsmagick.org/GraphicsMagick.html#details-raise
1006 proto.lower = function lower (w, h) {
1007 return this.out("+raise", (w||0)+"x"+(h||0));
1008 }
1009  
1010 // http://www.graphicsmagick.org/GraphicsMagick.html#details-region
1011 proto.region = function region (w, h, x, y) {
1012 w = w || 0;
1013 h = h || 0;
1014 x = x || 0;
1015 y = y || 0;
1016 return this.out("-region", w + "x" + h + "+" + x + "+" + y);
1017 }
1018  
1019 // http://www.graphicsmagick.org/GraphicsMagick.html#details-roll
1020 proto.roll = function roll (x, y) {
1021 x = ((x = parseInt(x, 10) || 0) >= 0 ? "+" : "") + x;
1022 y = ((y = parseInt(y, 10) || 0) >= 0 ? "+" : "") + y;
1023 return this.out("-roll", x+y);
1024 }
1025  
1026 // http://www.graphicsmagick.org/GraphicsMagick.html#details-sharpen
1027 proto.sharpen = function sharpen (radius, sigma) {
1028 sigma = sigma
1029 ? "x" + sigma
1030 : "";
1031  
1032 return this.out("-sharpen", radius + sigma);
1033 }
1034  
1035 // http://www.graphicsmagick.org/GraphicsMagick.html#details-solarize
1036 proto.solarize = function solarize (factor) {
1037 return this.out("-solarize", (factor || 1)+"%");
1038 }
1039  
1040 // http://www.graphicsmagick.org/GraphicsMagick.html#details-spread
1041 proto.spread = function spread (amount) {
1042 return this.out("-spread", amount || 5);
1043 }
1044  
1045 // http://www.graphicsmagick.org/GraphicsMagick.html#details-swirl
1046 proto.swirl = function swirl (degrees) {
1047 return this.out("-swirl", degrees || 180);
1048 }
1049  
1050 // http://www.graphicsmagick.org/GraphicsMagick.html#details-type
1051 proto.type = function type (type) {
1052 return this.in("-type", type);
1053 }
1054  
1055 // http://www.graphicsmagick.org/GraphicsMagick.html#details-trim
1056 proto.trim = function trim () {
1057 return this.out("-trim");
1058 }
1059  
1060 // http://www.graphicsmagick.org/GraphicsMagick.html#details-extent
1061 proto.extent = function extent (w, h, options) {
1062 options = options || "";
1063 var geometry;
1064 if (w && h) {
1065 geometry = w + "x" + h + options
1066 } else if (w && !h) {
1067 geometry = (this._options.imageMagick) ? w + options : w + 'x' + options;
1068 } else if (!w && h) {
1069 geometry = 'x' + h + options
1070 }
1071  
1072 return this.out("-extent", geometry);
1073 }
1074  
1075 // http://www.graphicsmagick.org/GraphicsMagick.html#details-gravity
1076 // Be sure to use gravity BEFORE extent
1077 proto.gravity = function gravity (type) {
1078 if (!type || !~gravity.types.indexOf(type)) {
1079 type = "NorthWest"; // Documented default.
1080 }
1081  
1082 return this.out("-gravity", type);
1083 }
1084  
1085 proto.gravity.types = [
1086 "NorthWest"
1087 , "North"
1088 , "NorthEast"
1089 , "West"
1090 , "Center"
1091 , "East"
1092 , "SouthWest"
1093 , "South"
1094 , "SouthEast"
1095 ];
1096  
1097 // http://www.graphicsmagick.org/GraphicsMagick.html#details-flatten
1098 proto.flatten = function flatten () {
1099 return this.out("-flatten");
1100 }
1101  
1102 // http://www.graphicsmagick.org/GraphicsMagick.html#details-background
1103 proto.background = function background (color) {
1104 return this.in("-background", color);
1105 }
1106 };
1107  
1108 /**
1109 * Generates a handler for comments/labels.
1110 */
1111  
1112 function comment (arg) {
1113 return function (format) {
1114 format = String(format);
1115  
1116 format = "@" == format.charAt(0)
1117 ? format.substring(1)
1118 : format;
1119  
1120 return this.out(arg, '"' + format + '"');
1121 }
1122 }