UNPKG

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