blob: 5e4d91233e1712ad8bbe37ace0e299cc45e21871 [file] [log] [blame]
cristy3eaa0ef2010-03-06 20:35:26 +00001
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
cristy2c839602010-04-03 02:32:08 +00004<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
cristy3eaa0ef2010-03-06 20:35:26 +00005<head>
cristy3de29cc2010-04-15 02:34:44 +00006 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
cristy3eaa0ef2010-03-06 20:35:26 +00007 <meta name="verify-v1" content="g222frIIxcQTrvDR3NBRUSKP3AnMNoqxOkIniCEkV7U=" />
8 <link rel="meta" type="application/rdf+xml" title="ICI" href="http://imagemagick.org/ici.rdf" />
cristy3de29cc2010-04-15 02:34:44 +00009 <style type="text/css" media="all">
cristy3eaa0ef2010-03-06 20:35:26 +000010 @import url("../www/magick.css");
cristy3de29cc2010-04-15 02:34:44 +000011 </style>
cristy3ed852e2009-09-05 21:47:34 +000012 <link rel="shortcut icon" href="../images/wand.ico" type="images/vnd.microsoft.icon"/>
13 <title>ImageMagick: The Fx Special Effects Image Operator</title>
14 <meta http-equiv="Content-Language" content="en-US"/>
15 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
16 <meta http-equiv="Reply-to" content="magick-users@imagemagick.org"/>
17 <meta name="Generator" content="PHP"/>
18 <meta name="Keywords" content="the, fx, special, effects, image, operator, ImageMagick, ImageMagic, MagickCore, MagickWand, PerlMagick, Magick++, RMagick, PythonMagick, JMagick, TclMagick, Image, Magick, Magic, Wand, ImageMagickObject, Swiss, Army, Knife, Image, Processing"/>
19 <meta name="Description" content="ImageMagick® is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (about 100) including GIF, JPEG, JPEG-2000, PNG, PDF, PhotoCD, TIFF, and DPX. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves. ImageMagick is free software delivered as a ready-to-run binary distribution or as source code that you can freely use, copy, modify, and distribute. Its license is compatible with the GPL. It runs on all major operating systems. The functionality of ImageMagick is typically utilized from the command line or you can use the features from programs written in your favorite programming language. Choose from these interfaces: MagickCore (C), MagickWand (C), ChMagick (Ch), Magick++ (C++), JMagick (Java), L-Magick (Lisp), PascalMagick (Pascal), PerlMagick (Perl), MagickWand for PHP (PHP), PythonMagick (Python), RMagick (Ruby), or TclMagick (Tcl/TK). With a language interface, use ImageMagick to modify or create images automagically and dynamically."/>
20 <meta name="Rating" content="GENERAL"/>
21 <meta name="Robots" content="INDEX, FOLLOW"/>
22 <meta name="Generator" content="ImageMagick Studio LLC"/>
23 <meta name="Author" content="ImageMagick Studio LLC"/>
24 <meta name="Revisit-after" content="2 DAYS"/>
25 <meta name="Resource-type" content="document"/>
cristy16af1cb2009-12-11 21:38:29 +000026 <meta name="Copyright" content="Copyright (c) 1999-2010 ImageMagick Studio LLC"/>
cristy3ed852e2009-09-05 21:47:34 +000027 <meta name="Distribution" content="Global"/>
cristy3eaa0ef2010-03-06 20:35:26 +000028</head>
29
30<body id="www-imagemagick-org">
31<div class="titlebar">
32<a href="../index.html">
33 <img src="../images/script.png" alt="[ImageMagick]"
34 style="width: 350px; height: 60px; margin: 28px auto; float: left;" /></a>
35<a href="http://www.networkredux.com">
36 <img src="../images/networkredux.png" alt="[sponsor]"
37 style="margin: 45px auto; border: 0px; float: left;" /></a>
38<a href="http://www.imagemagick.org/discourse-server/">
39 <img src="../images/logo.jpg" alt=""
40 style="width: 114px; height: 118px; border: 0px; float: right;" /></a>
41<a href="../index.html">
42 <img src="../images/sprite.jpg" alt=""
43 style="width: 114px; height: 118px; border: 0px; float: right;" /></a>
44</div>
45
cristyce69bb02010-07-27 19:49:46 +000046<div class="westbar">
cristy3eaa0ef2010-03-06 20:35:26 +000047
cristy3ed852e2009-09-05 21:47:34 +000048<div class="menu">
cristy83a272e2010-05-07 20:40:35 +000049 <a title="About ImageMagick" href="../index.html">About ImageMagick</a>
cristy3ed852e2009-09-05 21:47:34 +000050</div>
cristy3eaa0ef2010-03-06 20:35:26 +000051<div class="sep"></div>
cristy3ed852e2009-09-05 21:47:34 +000052<div class="menu">
cristybb503372010-05-27 20:51:26 +000053 <a title="Binary Releases" href="../www/binary-releases.html">Binary Releases</a>
54</div>
55<div class="sub">
56 <a title="Binary Release: Unix" href="../www/binary-releases.html#unix">Unix</a>
57</div>
58<div class="sub">
59 <a title="Binary Release: MacOS X" href="../www/binary-releases.html#macosx">Mac OS X</a>
60</div>
61<div class="sub">
62 <a title="Binary Release: Windows" href="../www/binary-releases.html#windows">Windows</a>
63</div>
64<div class="sep"></div>
65<div class="menu">
cristy83a272e2010-05-07 20:40:35 +000066 <a title="Command-line Tools" href="../www/command-line-tools.html">Command-line Tools</a>
cristy3ed852e2009-09-05 21:47:34 +000067</div>
68<div class="sub">
cristy83a272e2010-05-07 20:40:35 +000069 <a title="Command-line Tools: Processing" href="../www/command-line-processing.html">Processing</a>
cristy3ed852e2009-09-05 21:47:34 +000070</div>
71<div class="sub">
cristy83a272e2010-05-07 20:40:35 +000072 <a title="Command-line Tools: Options" href="../www/command-line-options.html">Options</a>
cristy3ed852e2009-09-05 21:47:34 +000073</div>
74<div class="sub">
cristy83a272e2010-05-07 20:40:35 +000075 <a title="Command-line Tools: Usage" href="http://www.imagemagick.org/Usage/">Usage</a>
cristy3ed852e2009-09-05 21:47:34 +000076</div>
77<div class="menu">
cristy83a272e2010-05-07 20:40:35 +000078 <a title="Program Interfaces" href="../www/api.html">Program Interfaces</a>
cristy3ed852e2009-09-05 21:47:34 +000079</div>
80<div class="sub">
cristy83a272e2010-05-07 20:40:35 +000081 <a title="Program Interface: MagickWand" href="../www/magick-wand.html">MagickWand</a>
cristy3ed852e2009-09-05 21:47:34 +000082</div>
83<div class="sub">
cristy83a272e2010-05-07 20:40:35 +000084 <a title="Program Interface: MagickCore" href="../www/magick-core.html">MagickCore</a>
cristy3ed852e2009-09-05 21:47:34 +000085</div>
86<div class="sub">
cristy83a272e2010-05-07 20:40:35 +000087 <a title="Program Interface: PerlMagick" href="../www/perl-magick.html">PerlMagick</a>
cristy3ed852e2009-09-05 21:47:34 +000088</div>
89<div class="sub">
cristy83a272e2010-05-07 20:40:35 +000090 <a title="Program Interface: Magick++" href="../Magick++/">Magick++</a>
cristy3ed852e2009-09-05 21:47:34 +000091</div>
cristy3eaa0ef2010-03-06 20:35:26 +000092<div class="sep"></div>
cristy3ed852e2009-09-05 21:47:34 +000093<div class="menu">
cristy83a272e2010-05-07 20:40:35 +000094 <a title="Install from Source" href="../www/install-source.html">Install from Source</a>
cristy3ed852e2009-09-05 21:47:34 +000095</div>
96<div class="sub">
cristy83a272e2010-05-07 20:40:35 +000097 <a title="Install from Source: Unix" href="../www/install-source.html#unix">Unix</a>
cristy3ed852e2009-09-05 21:47:34 +000098</div>
99<div class="sub">
cristy83a272e2010-05-07 20:40:35 +0000100 <a title="Install from Source: Windows" href="../www/install-source.html#windows">Windows</a>
cristy3ed852e2009-09-05 21:47:34 +0000101 </div>
102<div class="menu">
cristy83a272e2010-05-07 20:40:35 +0000103 <a title="Resources" href="../www/resources.html">Resources</a>
cristy3ed852e2009-09-05 21:47:34 +0000104</div>
cristybb503372010-05-27 20:51:26 +0000105<div class="menu">
106 <a title="Architecture" href="../www/architecture.html">Architecture</a>
107</div>
cristy3ed852e2009-09-05 21:47:34 +0000108<div class="menu">
cristy83a272e2010-05-07 20:40:35 +0000109 <a title="Download" href="../www/download.html">Download</a>
cristy3ed852e2009-09-05 21:47:34 +0000110</div>
cristy3eaa0ef2010-03-06 20:35:26 +0000111<div class="sep"></div>
cristy3ed852e2009-09-05 21:47:34 +0000112<div class="menu">
cristy83a272e2010-05-07 20:40:35 +0000113 <a title="Search" href="http://www.imagemagick.org/script/search.php">Search</a>
cristy3ed852e2009-09-05 21:47:34 +0000114</div>
cristy3eaa0ef2010-03-06 20:35:26 +0000115<div class="sep"></div>
cristy3ed852e2009-09-05 21:47:34 +0000116<div class="menu">
cristy83a272e2010-05-07 20:40:35 +0000117 <a title="Site Map"href="../www/sitemap.html">Site Map</a>
cristy3ed852e2009-09-05 21:47:34 +0000118</div>
119<div class="sub">
cristy83a272e2010-05-07 20:40:35 +0000120 <a title="Site Map: Links"href="../www/links.html">Links</a>
cristy3ed852e2009-09-05 21:47:34 +0000121</div>
cristy3eaa0ef2010-03-06 20:35:26 +0000122<div class="sep"></div>
cristy3ed852e2009-09-05 21:47:34 +0000123<div class="menu">
cristy83a272e2010-05-07 20:40:35 +0000124 <a title="Sponsors" href="../www/sponsors.html">Sponsors:</a>
cristy3ed852e2009-09-05 21:47:34 +0000125
126<div class="sponsbox">
127<div class="sponsor">
cristy83a272e2010-05-07 20:40:35 +0000128 <a title="Sponsor: Webdesign Agentur" href="http://www.ventzke-partner.de">Webdesign Agentur</a><!-- 201101010480 invendio.de-->
cristy8f900122010-03-05 15:26:31 +0000129</div>
130<div class="sponsor">
cristy83a272e2010-05-07 20:40:35 +0000131 <a title="Sponsor: LVM Versicherung" href="http://www.neu-reich.de">LVM Versicherung</a><!-- 201101010480 -->
cristycdbe2742010-02-07 19:30:44 +0000132</div>
133<div class="sponsor">
cristy83a272e2010-05-07 20:40:35 +0000134 <a title="Sponsor: Deko.net" href="http://www.deko.net">Deko.net</a><!-- 201101010600 Peterssen-->
cristy5f2356f2009-11-16 00:40:46 +0000135</div>
136<div class="sponsor">
cristy83a272e2010-05-07 20:40:35 +0000137 <a title="Sponsor: Druckerei" href="http://www.print24.de/">Druckerei</a><!-- 201009010720 -->
cristyc1c61662009-09-30 14:04:37 +0000138</div>
139<div class="sponsor">
cristy83a272e2010-05-07 20:40:35 +0000140 <a title="Sponsor: Druckerei Online" href="http://www.allesdruck.de">Druckerei Online</a><!-- 201012011200 allesdruck.de-->
cristyb4c03bb2009-09-27 13:55:46 +0000141</div>
cristyce69bb02010-07-27 19:49:46 +0000142<div class="sponsor">
143 <a title="Sponsor: Online-Magazin" href="http://www.unkostenbeitrag.de/">Online-Magazin</a><!-- 20101101000200 -->
cristy3ed852e2009-09-05 21:47:34 +0000144</div>
145</div>
cristyce69bb02010-07-27 19:49:46 +0000146</div>
147</div>
cristy3eaa0ef2010-03-06 20:35:26 +0000148
cristyce69bb02010-07-27 19:49:46 +0000149<div class="eastbar">
150 <script type="text/javascript">
151 <!--
152 google_ad_client = "pub-3129977114552745";
153 /* 160x600, created 7/27/10 */
154 google_ad_slot = "0574824969";
155 google_ad_width = 160;
156 google_ad_height = 600;
157 //-->
158 </script>
159 <script type="text/javascript"
160 src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
161 </script>
cristy3eaa0ef2010-03-06 20:35:26 +0000162</div>
163
164<div class="main">
165
cristy3ed852e2009-09-05 21:47:34 +0000166<p class="navigation-index">[<a href="#fx">The Fx Special Effects Image Operator</a> &bull; <a href="#anatomy">The Anatomy of an Fx Expression</a>]</p>
167
168<h2><a name="fx"></a>The Fx Special Effects Image Operator</h2>
169<div class="doc-section">
170
171<p>Use the Fx special effects image operator to apply a mathematical expression to an image or image channels. Use Fx to:</p>
172
173<ul>
174 <li>create canvases, gradients, mathematical colormaps</li>
175 <li>move color values between images and channels</li>
176 <li>translate, flip, mirror, rotate, scale, shear and generally distort images</li>
177 <li>merge or composite multiple images together</li>
178 <li>convolve or merge neighboring pixels together</li>
179 <li>generate image metrics or 'fingerprints'</li>
180</ul>
181
182<p>The expression can be simple:</p>
183
184<p class='crt'><span class="crtprompt"> $magick&gt; </span><span class='crtin'>convert -size 64x64 xc:black -channel blue -fx "1/2" fx_navy.png</span></p>
185<p>Here, we convert a black to a navy blue image:</p>
186
187<p class="image">
188 <a href="../images/black.png"><img src="../images/black.png" width="64" height="64" alt="black" /></a>
189 <img style="margin-top:22px; margin-bottom:22px;" src="../images/right.gif" width="20" height="20" alt="==>" />
190 <a href="../images/navy.png"><img src="../images/navy.png" width="64" height="64" alt="navy" /></a>
191</p>
192
193<p>Or the expression can be complex:</p>
194
195<p class='crt'><span class="crtprompt"> $magick&gt; </span><span class='crtin'>convert rose.jpg \ <br/>
196 -fx "(1.0/(1.0+exp(10.0*(0.5-u)))-0.006693)*1.0092503" \ <br/>
197 rose-sigmoidal.png</span></p>
198<p>This expression results in a high contrast version of the image:</p>
199
200<p class="image">
201 <a href="../images/rose.jpg"><img src="../images/rose.jpg" width="70" height="46" alt="rose" /></a>
202 <img style="margin-top:13px; margin-bottom:13px;" src="../images/right.gif" width="20" height="20" alt="==>" />
203 <a href="../images/rose-sigmoidal.png"><img src="../images/rose-sigmoidal.png" width="70" height="46" alt="rose-sigmoidal" /></a>
204</p>
205
206<p>The expression can include variable assignments. Assignments, in most cases, reduce the complexity of an expression and permit some operations that might not be possible any other way. For example, lets create a radial gradient:</p>
207
208<p class='crt'><span class="crtprompt"> $magick&gt; </span><span class='crtin'>convert -size 70x70 xc: \ <br/>
209 -fx "Xi=i-w/2; Yj=j-h/2; 1.2*(0.5-hypot(Xi,Yj)/70.0)+0.5" \ <br/>
210 radial-gradient.png</span></p>
211<p>The command above returns this image:</p>
212
213<p class="image">
214 <a href="../images/radial-gradient.png"><img src="../images/radial-gradient.png" width="70" height="70" alt="radial-gradient" /></a>
215</p>
216<p>See <a href="http://www.imagemagick.org/Usage/transform/index.html#fx">Using FX, The Special Effects Image Operator</a> for more examples.</p>
217
218<p>The next section discusses the Fx expression language.</p>
219
220</div>
221
222<h2><a name="anatomy"></a>The Anatomy of an Fx Expression</h2>
223<div class="doc-section">
224
225<h3>The Fx Expression Language</h3>
226<div class="doc-section">
227
228<p>The formal Fx expression language is defined here:</p>
229
230<dl class="doc">
231 <dt class="doc"> numbers:</dt>
232 <dd> integer, floating point, or scientfic notation (+/- required, e.g. 3.81469e-06)</dd>
233 <dt class="doc"> constants: </dt>
234 <dd> e, Epsilon, QuantumRange, QuantumScale, Opaque, Pi, Transparent</dd>
235 <dt class="doc"> Fx operators (in order of precedence): </dt>
236 <dd> ^ (power), *, /, % (modulo), +, -,
237 &lt;&lt;, &gt;&gt;, &lt;, &lt;=, &gt;, &gt;=, ==, !=,
238 &amp; (bitwise AND), | (bitwise OR),
239 &amp;&amp; (logical AND), || (logical OR),
240 ~ (logical NOT), ?: (ternary conditional)</dd>
241 <dt class="doc"> math functions: </dt>
cristy19156992010-03-04 17:04:59 +0000242 <dd> abs(), acos(), airy(), alt(), asin(), atan(), atan2(), ceil(), cos(), cosh(), debug(), exp(), floor(),
243 hypot(), int(), j0(), j1(), jinc(), ln(), log(), logtwo(), max(), min(), mod(), pow(), rand(), round(),
244 sign(), sin(), sinc(), sinh(), sqrt(), tan(), tanh()</dd>
cristy3ed852e2009-09-05 21:47:34 +0000245 <dt class="doc"> channel functions: </dt>
246 <dd> channel(r,g,b,a), channel(c,m,y,k,a)</dd>
247 <dt class="doc"> color names:</dt>
248 <dd> red, cyan, black, etc.</dd>
249 <dt class="doc"> color functions:</dt>
250 <dd> rgb(), rgba(), cmyk(), cmyka(), hsl(), hsla()</dd>
251 <dt class="doc"> color hex values:</dt>
252 <dd> #ccc, #cbfed0, #b9e1cc00</dd>
253 <dt class="doc"> symbols:</dt>
254 <dd style="white-space:pre">
255 s = current image in sequence
256 t = scene number of current image in sequence
257 u = first image in sequence
258 v = second image in sequence
259 n = number of images in sequence
260
261 i = column offset
262 j = row offset
263 p = pixel to use (absolute or relative to current pixel)
264
265 w = width of this image
266 h = height of this image
267 z = channel depth
268
269 r = red value (from RGBA), of a specific or current pixel
270 g = green ''
271 b = blue ''
272 a = alpha ''
273 o = opacity ''
274
275 c = cyan value of CMYK color of pixel
276 y = yellow ''
277 m = magenta ''
278 k = black ''
279
280 intensity = pixel intensity
281
282 hue = pixel hue
283 saturation = pixel saturation
284 lightness = pixel lightness
285 luminance = pixel luminance
286
287 page.width = page width
288 page.height = page height
289 page.x = page x offset
290 page.y = page y offset
291
292 resolution.x = x resolution
293 resolution.y = y resolution
294
295 depth = image depth
296 minima = image minima
297 maxima = image maxima
298 mean = image mean
299 standard_deviation = image standard deviation
300 kurtosis = image kurtosis
301 skewness = image skewness
302 (add a channel specifier to compute a statistic for that channel, e.g. depth.r)
303 </dd>
304</dl>
305
306</div>
307
308<h3>The Fx Expression</h3>
309<div class="doc-section">
310
311<p>An Fx expression may include any combination of the following:</p>
312<ul>
313<li> <em>x</em> <kbd>^</kbd> <em>y</em>: exponentiation (<em>x<sup>y</sup></em>)</li>
314<li> <kbd>(</kbd> ... <kbd>)</kbd>: grouping</li>
315<li> <em>x</em> <kbd>*</kbd> <em>y</em>: multiplication (the asterisk <kbd>*</kbd> is optional, for example, <kbd>2u</kbd> or <kbd>2(x+y)</kbd> are acceptable)</li>
316<li> <em>x</em> <kbd>/</kbd> <em>y</em>: division</li>
317<li> <em>x</em> <kbd>%</kbd> <em>y</em>: modulo</li>
318<li> <em>x</em> <kbd>+</kbd> <em>y</em>: addition</li>
319<li> <em>x</em> <kbd>-</kbd> <em>y</em>: subtraction</li>
320<li> <em>x</em> <kbd>&lt;&lt;</kbd> <em>y</em>: left shift</li>
321<li> <em>x</em> <kbd>&gt;&gt;</kbd> <em>y</em>: right shift</li>
322<li> <em>x</em> <kbd>&lt;</kbd> <em>y</em>: boolean relation, return value 1.0 if <em>x</em> &lt; <em>y</em>, otherwise 0.0</li>
323<li> <em>x</em> <kbd>&lt;=</kbd> <em>y</em>: boolean relation, return value 1.0 if <em>x</em> &lt;= <em>y</em>, otherwise 0.0</li>
324<li> <em>x</em> <kbd>&gt;</kbd> <em>y</em>: boolean relation, return value 1.0 if <em>x</em> &gt; <em>y</em>, otherwise 0.0</li>
325<li> <em>x</em> <kbd>&gt;=</kbd> <em>y</em>: boolean relation, return value 1.0 if <em>x</em> &gt;= <em>y</em>, otherwise 0.0</li>
326<li> <em>x</em> <kbd>==</kbd> <em>y</em>: boolean relation, return value 1.0 if <em>x </em>==<em> y</em>, otherwise 0.0</li>
327<li> <em>x</em> <kbd>!=</kbd> <em>y</em>: boolean relation, return value 1.0 if <em>x </em>!=<em> y</em>, otherwise 0.0</li>
328<li> <em>x</em> <kbd>&amp;</kbd> <em>y</em>: binary AND</li>
329<li> <em>x</em> <kbd>|</kbd> <em>y</em>: binary OR</li>
330<li> <em>x</em> <kbd>&amp;&amp;</kbd> <em>y</em>: logical AND connective, return value 1.0 if <em>x</em> &gt; 0 and <em>y</em> &gt; 0, otherwise 0.0</li>
331<li> <em>x</em> <kbd>||</kbd> <em>y</em>: logical OR connective (inclusive), return value 1.0 if <em>x</em> &gt; 0 or <em>y</em> &gt; 0 (or both), otherwise 0.0</li>
332<li> <kbd>~</kbd><em>x</em>: logical NOT operator, return value 1.0 if <em>not</em> <em>x</em> &gt; 0, otherwise 0.0</li>
333<li> <kbd>+</kbd><em>x</em>: unary plus, return 1.0*value</li>
334<li> <kbd>-</kbd><em>x</em>: unary minus, return -1.0*value</li>
335<li> <em>x</em> <kbd>?</kbd> <em>y</em> : <em>z</em>: ternary conditional expression, return value <em>y</em> if <em>x</em> != 0, otherwise <em>z</em>; only one ternary conditional permitted per statement</li>
336<li> <em>x</em> <kbd>=</kbd> <em>y</em>: assignment; assignment variables are restricted to letter combinations only (e.g. Xi not X1)</li>
337<li> <em>x</em> <kbd>;</kbd> <em>y</em>: statement separator </li>
338<li> <kbd>pi</kbd>: constant (3.141659...)</li>
339<li> <kbd>e</kbd>: constant (2.71828...)</li>
340<li> <kbd>QuantumRange</kbd>: constant maximum pixel value (255 for Q8, 65535 for Q16)</li>
341<li> <kbd>QuantumScale</kbd>: constant 1.0/<kbd>QuantumRange</kbd></li>
342<li> <kbd>intensity</kbd>: pixel intensity; equivalent to 0.299*red+0.587*green+0.114*blue</li>
343<li> <kbd>hue</kbd>: pixel hue</li>
344<li> <kbd>saturation</kbd>: pixel saturation</li>
345<li> <kbd>lightness</kbd>: pixel lightness; equivalent to 0.5*max(red,green,blue) + 0.5*min(red,green,blue)</li>
346<li> <kbd>luminance</kbd>: pixel luminance; equivalent to 0.2126*red + 0.7152*green + 0.0722*blue</li>
347<li> <kbd>red, green, blue</kbd>, etc.: color names</li>
348<li> <kbd>#ccc, #cbfed0, #b9e1cc00</kbd>, etc.: color hex values</li>
349<li> <kbd>rgb(), rgba(), cmyk(), cmyka(), hsl(), hsla()</kbd>: color functions</li>
350<li> <kbd>s, t, u, v, n, i, j, w, h, z, r, g, b, a, o, c, y, m, k</kbd>: symbols</li>
351<li> <kbd>abs(</kbd><em>x</em><kbd>)</kbd>: absolute value function</li>
352<li> <kbd>acos(</kbd><em>x</em><kbd>)</kbd>: arc cosine function</li>
cristy2c839602010-04-03 02:32:08 +0000353<li> <kbd>airy(</kbd><em>x</em><kbd>)</kbd>: Airy function (max=1, min=0); <kbd>airy(</kbd><em>x</em><kbd>)</kbd>=<kbd>[jinc(</kbd><em>x</em><kbd>)]<sup>2</sup></kbd>=<kbd>[2*j1(</kbd><em>pi*x</em><kbd>)/(</kbd><em>pi*x</em><kbd>)]<sup>2</sup></kbd></li>
cristy3ed852e2009-09-05 21:47:34 +0000354<li> <kbd>alt(</kbd><em>x</em><kbd>)</kbd>: sign alternation function (return 1.0 if <kbd>int(</kbd><em>x</em><kbd>)</kbd> is even, -1.0 if <kbd>int(</kbd><em>x</em><kbd>)</kbd> is odd)</li>
355<li> <kbd>asin(</kbd><em>x</em><kbd>)</kbd>: arc sine function</li>
356<li> <kbd>atan(</kbd><em>x</em><kbd>)</kbd>: arc tangent function</li>
357<li> <kbd>atan2(</kbd><em>y</em>,<em>x</em><kbd>)</kbd>: arc tangent function of two variables</li>
358<li> <kbd>ceil(</kbd><em>x</em><kbd>)</kbd>: smallest integral value not less than argument</li>
359<li> <kbd>channel(</kbd><em>r</em>,<em>g</em>,<em>b</em>,<em>a</em><kbd>)</kbd>: select numeric argument based on current channel</li>
360<li> <kbd>channel(</kbd><em>c</em>,<em>m</em>,<em>y</em>,<em>k</em>,<em>a</em><kbd>)</kbd>: select numeric argument based on current channel</li>
361<li> <kbd>cos(</kbd><em>x</em><kbd>)</kbd>: cosine function</li>
362<li> <kbd>cosh(</kbd><em>x</em><kbd>)</kbd>: hyperbolic cosine function</li>
363<li> <kbd>debug(</kbd><em>x</em><kbd>)</kbd>: print <em>x</em> (useful for debugging your expression)</li>
364<li> <kbd>exp(</kbd><em>x</em><kbd>)</kbd>: natural exponential function (<em>e<sup>x</sup></em>)</li>
365<li> <kbd>floor(</kbd><em>x</em><kbd>)</kbd>: largest integral value not greater than argument</li>
366<li> <kbd>hypot(</kbd><em>x</em>,<em>y</em><kbd>)</kbd>: the square root of x<sup>2</sup>+y<sup>2</sup></li>
367<li> <kbd>int(</kbd><em>x</em><kbd>)</kbd>: greatest integer function (return greatest integer less than or equal to <em>x</em>)</li>
cristy2c839602010-04-03 02:32:08 +0000368<li> <kbd>j0(</kbd><em>x</em><kbd>)</kbd>: Bessel functions of <em>x</em> of the first kind of order 0</li>
369<li> <kbd>j1(</kbd><em>x</em><kbd>)</kbd>: Bessel functions of <em>x</em> of the first kind of order 1</li>
cristy4949d522010-03-12 18:41:34 +0000370<li> <kbd>jinc(</kbd><em>x</em><kbd>)</kbd>: jinc function (max=1, min=-0.1323); <kbd>jinc(</kbd><em>x</em><kbd>)</kbd>=<kbd>2*j1(</kbd><em>pi*x</em><kbd>)/(</kbd><em>pi*x</em><kbd>)</kbd></li>
cristy3ed852e2009-09-05 21:47:34 +0000371<li> <kbd>ln(</kbd><em>x</em><kbd>)</kbd>: natural logarithm function</li>
372<li> <kbd>log(</kbd><em>x</em><kbd>)</kbd>: logarithm base 10</li>
373<li> <kbd>logtwo(</kbd><em>x</em><kbd>)</kbd>: logarithm base 2</li>
374<li> <kbd>ln(</kbd><em>x</em><kbd>)</kbd>: natural logarithm</li>
375<li> <kbd>max(</kbd><em>x</em>, <em>y</em><kbd>)</kbd>: maximum of <em>x</em> and <em>y</em></li>
376<li> <kbd>min(</kbd><em>x</em>, <em>y</em><kbd>)</kbd>: minimum of <em>x</em> and <em>y</em></li>
377<li> <kbd>mod(</kbd><em>x</em>, <em>y</em><kbd>)</kbd>: floating-point remainder function</li>
378<li> <kbd>pow(</kbd><em>x</em>,<em>y</em><kbd>)</kbd>: power function (<em>x<sup>y</sup></em>)</li>
379<li> <kbd>rand()</kbd>: value uniformly distributed over the interval [0.0, 1.0) with a 2 to the 128th-1 period</li>
380<li> <kbd>round()</kbd>: round to integral value, regardless of rounding direction</li>
381<li> <kbd>sign(</kbd><em>x</em><kbd>)</kbd>: return -1.0 if <em>x</em> is less than 0.0 otherwise 1.0</li>
382<li> <kbd>sin(</kbd><em>x</em><kbd>)</kbd>: sine function</li>
cristy2c2a4492010-03-16 15:06:03 +0000383<li> <kbd>sinc(</kbd><em>x</em><kbd>)</kbd>: sinc function (max=1, min=-0.21); <kbd>sinc(</kbd><em>x</em><kbd>)</kbd>=<kbd>sin(</kbd><em>pi*x</em><kbd>)/(</kbd><em>pi*x</em><kbd>)</kbd></li>
cristy3ed852e2009-09-05 21:47:34 +0000384<li> <kbd>sinh(</kbd><em>x</em><kbd>)</kbd>: hyperbolic sine function</li>
385<li> <kbd>sqrt(</kbd><em>x</em><kbd>)</kbd>: square root function</li>
386<li> <kbd>tan(</kbd><em>x</em><kbd>)</kbd>: tangent function</li>
387<li> <kbd>tanh(</kbd><em>x</em><kbd>)</kbd>: hyperbolic tangent function</li>
388</ul>
389
390<p>The expression semantics include these rules:</p>
391
392<ul>
393<li>symbols are case insensitive</li>
394<li>only one ternary conditional (e.g. x ? y : z) per statement</li>
395<li>statements are assignments or the final expression to return</li>
396<li>an assignment starts a statement, it is not an operator</li>
397<li>assignments to built-ins do not throw an exception and have no effect; e.g. <kbd>r=3.0; r</kbd> returns the pixel red color value, not 3.0</li>
398</ul>
399
400</div>
401
402<h3>Source Images</h3>
403<div class="doc-section">
404
405<p>The symbols <kbd>u</kbd> and <kbd>v</kbd> refer to the first and second images, respectively, in the current image sequence. Refer to a particular image in a sequence by appending its index to any image reference (usually <kbd>u</kbd>), with a zero index for the beginning of the sequence. A negative index counts from the end. For example, <kbd>u[0]</kbd> is the first image in the sequence, <kbd>u[2]</kbd> is the third, <kbd>u[-1]</kbd> is the last image, and <kbd>u[t]</kbd> is the current image. The current image can also be referenced by <kbd>s</kbd>. If the sequence number exceeds the length of the sequence, the count is wrapped. Thus in a 3-image sequence, <kbd>u[-1]</kbd>, <kbd>u[2]</kbd>, and <kbd>u[5]</kbd> all refer to the same (third) image.</p>
406
407<p>As an example, we form an image by averaging the first image and third images:</p>
408
409<p class='crt'><span class="crtprompt"> $magick&gt; </span><span class='crtin'>convert image1.jpg image2.jpg image3.jpg -fx "(u+u[2])/2.0" image.jpg</span></p>
410<p>By default, the image to which <kbd>p</kbd>, <kbd>r</kbd>, <kbd>g</kbd>, <kbd>b</kbd>, <kbd>a</kbd>, etc., are applied is the first image <kbd>u</kbd> in the image list, which may also be referenced using <kbd>s</kbd>. </p>
411
cristy19156992010-03-04 17:04:59 +0000412<p>It is important to note the special role played by the first image. This is the only image in the image sequence that is modified, other images are used only for their data. As an illustrative example, consider the following, and note that the setting <a href="../www/command-line-options.html#channel">-channel red</a> instructs <a href="../www/command-line-options.html#fx">-fx</a> to modify only the red channel; nothing in the green or blue channels will change. It is instructive to ponder why the result is not symmetric.</p>
cristy3ed852e2009-09-05 21:47:34 +0000413
414<p class='crt'><span class="crtprompt"> $magick&gt; </span><span class='crtin'>convert -channel red logo: -flop logo: -resize "20%" -fx "(u+v)/2" image.jpg</span></p>
415<div class="image">
416<p>
417 <a href="../images/logo-sm-flop.png"><img src="../images/logo-sm-flop.png" width="128" height="96" alt="logo-sm-flop.png" /></a>
418 <a href="../images/logo-sm.png"><img src="../images/logo-sm.png" width="128" height="96" alt="logo-sm.png" /></a>
419<img style="margin-top:38px; margin-bottom:38px;" src="../images/right.gif" width="20" height="20" alt="==>" />
420 <a href="../images/logo-sm-fx.png"><img src="../images/logo-sm-fx.png" width="128" height="96" alt="logo-sm-fx.png" /></a>
421</p>
422</div>
423
424
425</div>
426
427<h3>Accessing Pixels</h3>
428<div class="doc-section">
429
430<p>All color values are normalized to the range of 0.0 to 1.0. The alpha channel ranges from 0.0 (fully transparent) to 1.0 (fully opaque).</p>
431
432<p>The pixels are processed one at a time, but a different pixel of an image can be specified using a pixel index represented by <kbd>p</kbd>. For example,</p>
433
434<pre class="text">
435 p[-1].g green value of pixel to the immediate left of the current pixel
436 p[-1,-1].r red value of the pixel diagonally left and up from current pixel
437</pre>
438
439<p>To specify an absolute position, use braces, rather than brackets.</p>
440
441<pre class="text">
442 p{0,0}.r red value of the pixel in the upper left corner of the image
443 p{12,34}.b blue pixel value at column number 12, row 34 of the image
444</pre>
445
446<p>Integer values of the position retrieve the color of the pixel referenced, while non-integer position values return a blended color according to the current <a href="../www/command-line-options.html#interpolate">-interpolate</a> setting.</p>
447
448<p>A position outside the boundary of the image retrieves a value dictated by the <a href="../www/command-line-options.html#virtual-pixel">-virtual-pixel</a> option setting.</p>
449
450</div>
451
452<h3>Apply an Expression to Select Image Channels</h3>
453<div class="doc-section">
454
455<p>Use the <a href="../www/command-line-options.html#channel">-channel</a> setting to specify the output channel of the result. If no output channel is given, the result is set over all channels except the opacity channel. For example, to replace the red channel of <kbd>alpha.png</kbd> with the average of the green channels from the images <kbd>alpha.png</kbd> and <kbd>beta.png</kbd>, use:</p>
456
457<p class='crt'><span class="crtprompt"> $magick&gt; </span><span class='crtin'>convert alpha.png beta.png -channel red -fx "(u.g+v.g)/2" gamma.png</span></p>
458</div>
459
460<h3>Results</h3>
461<div class="doc-section">
462
463<p>The <a href="../www/command-line-options.html#fx">-fx</a> operator evaluates the given expression for each channel (set by <a href="../www/command-line-options.html#channel">-channel</a>) of each pixel in the first image (<kbd>u</kbd>) in the sequence. The computed values are temporarily stored in a copy (clone) of that first image until all the pixels have been processed, after which this single new image replaces the list of images in the current image sequence. As such, in the previous example the updated version of <kbd>alpha.png</kbd> replaces both of the original images, <kbd>alpha.png</kbd> and <kbd>beta.png</kbd>, before being saved as <kbd>gamma.png</kbd>.</p>
464
465<p>The current image <kbd>s</kbd> is set to the first image in the sequence (<kbd>u</kbd>), and <kbd>t</kbd> to its index, 0. The symbols <kbd>i</kbd> and <kbd>j</kbd> reference the current pixel being processed.</p>
466
467
468<p>For use with <a href="../www/command-line-options.html#format_identify_">-format</a>, the value-escape <kbd>%[fx: ]</kbd> is evaluated just once for each image in the current image sequence. As each image in the sequence is being evaluated, <kbd>s</kbd> and <kbd>t</kbd> successively refer to the current image and its index, while <kbd>i</kbd> and <kbd>j</kbd> are set to zero, and the current channel set to red (<a href="../www/command-line-options.html#channel">-channel</a> is ignored). An example:</p>
469
470<p class='crt'><span class="crtprompt"> $magick&gt; </span><span class='crtin'>convert xc:'rgb(25%,50%,75%)' rose: -colorspace rgb \ <br/>
471 -format 'Red channel of NW corner of image # %[fx:t] is %[fx: s]' info:</span><span class='crtout'>Red channel of NW corner of image # 0 is 0.250004 <br/>
472 Red channel of NW corner of image # 1 is 0.188235</span></p>
cristyfe7ce342010-06-22 15:41:50 +0000473<p>Use <kbd>%[fxc: ]</kbd> if your expression is a constant (e.g. <kbd>%[fxc:page.x/2]</kbd>. The result is cached and the cached result returned rather than evaluating the expression each time.</p>
474
cristy3ed852e2009-09-05 21:47:34 +0000475<p>The color-escape <kbd>%[pixel: ]</kbd> is evaluated once per image and per color channel in that image (<a href="../www/command-line-options.html#channel">-channel</a> is ignored), The values generated are then converted into a color string (a named color or hex color value). The symbols <kbd>i</kbd> and <kbd>j</kbd> are set to zero, and <kbd>s</kbd> and <kbd>t</kbd> refer to each successively current image and index.</p>
476
477</div>
478</div>
cristy3eaa0ef2010-03-06 20:35:26 +0000479
480</div>
481
482<div id="linkbar">
cristyce69bb02010-07-27 19:49:46 +0000483 <span id="linkbar-west">&nbsp;</span>
cristy3eaa0ef2010-03-06 20:35:26 +0000484 <span id="linkbar-center">
485 <a href="http://www.imagemagick.org/discourse-server/">Discourse Server</a> &bull;
cristya8902942010-07-30 00:49:52 +0000486 <a href="http://www.imagemagick.org/MagickStudio/scripts/MagickStudio.cgi">Studio</a>
cristy3eaa0ef2010-03-06 20:35:26 +0000487 </span>
488 <span id="linkbar-east">&nbsp;</span>
489 </div>
490 <div class="footer">
491 <span id="footer-west">&copy; 1999-2010 ImageMagick Studio LLC</span>
492 <span id="footer-east"> <a href="http://www.imagemagick.org/script/contact.php">Contact the Wizards</a></span>
493 </div>
494 <div style="clear: both; margin: 0; width: 100%; "></div>
cristya8902942010-07-30 00:49:52 +0000495 <script type="text/javascript">
496 var _gaq = _gaq || [];
497 _gaq.push(['_setAccount', 'UA-17690367-1']);
498 _gaq.push(['_trackPageview']);
499
500 (function() {
501 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
502 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
503 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
504 })();
505 </script>
cristy3eaa0ef2010-03-06 20:35:26 +0000506</body>
507</html>