args.js 33 KB

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