blob: 366d4e784d0ca3afd73ce77d159d9f554c4a3844 [file] [log] [blame]
cristy3eaa0ef2010-03-06 20:35:26 +00001
cristydcca3fa2010-12-29 21:50:07 +00002<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
cristy2bd2a982011-02-15 00:52:58 +00004<html version="-//W3C//DTD XHTML 1.1//EN"
5 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
6 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7 xsi:schemaLocation="http://www.w3.org/1999/xhtml
8 http://www.w3.org/MarkUp/SCHEMA/xhtml11.xsd">
cristy3eaa0ef2010-03-06 20:35:26 +00009<head>
cristy3c98a4f2010-08-13 20:09:41 +000010 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
11 <meta name="verify-v1" content="g222frIIxcQTrvDR3NBRUSKP3AnMNoqxOkIniCEkV7U="/>
cristyffb69ed2010-12-25 00:06:48 +000012 <title>ImageMagick: The Fx Special Effects Image Operator</title>
cristy3ed852e2009-09-05 21:47:34 +000013 <meta http-equiv="Content-Language" content="en-US"/>
14 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
15 <meta http-equiv="Reply-to" content="magick-users@imagemagick.org"/>
cristy3c98a4f2010-08-13 20:09:41 +000016 <meta name="Application-name" content="ImageMagick"/>
cristyaf8d6652011-02-04 21:57:45 +000017 <meta name="Description" content="Use ImageMagick to convert, edit, or compose bitmap images in a variety of formats. In addition resize, rotate, shear, distort and transform images."/>
cristy3c98a4f2010-08-13 20:09:41 +000018 <meta name="Application-url" content="http://www.imagemagick.org"/>
cristy3ed852e2009-09-05 21:47:34 +000019 <meta name="Generator" content="PHP"/>
20 <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"/>
cristy3ed852e2009-09-05 21:47:34 +000021 <meta name="Rating" content="GENERAL"/>
22 <meta name="Robots" content="INDEX, FOLLOW"/>
23 <meta name="Generator" content="ImageMagick Studio LLC"/>
24 <meta name="Author" content="ImageMagick Studio LLC"/>
25 <meta name="Revisit-after" content="2 DAYS"/>
26 <meta name="Resource-type" content="document"/>
cristy7e41fe82010-12-04 23:12:08 +000027 <meta name="Copyright" content="Copyright (c) 1999-2011 ImageMagick Studio LLC"/>
cristy3ed852e2009-09-05 21:47:34 +000028 <meta name="Distribution" content="Global"/>
cristydcca3fa2010-12-29 21:50:07 +000029 <link rel="icon" href="../images/wand.png"/>
cristy3c98a4f2010-08-13 20:09:41 +000030 <link rel="shortcut icon" href="../images/wand.ico" type="images/x-icon"/>
31 <link rel="meta" type="application/rdf+xml" title="ICI" href="http://imagemagick.org/ici.rdf"/>
cristy7a40ba82011-01-08 20:31:18 +000032 <link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css" type="text/css" />
cristy3c98a4f2010-08-13 20:09:41 +000033 <style type="text/css" media="all">
34 @import url("../www/magick.css");
35 </style>
cristydcca3fa2010-12-29 21:50:07 +000036 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
cristy361f4662010-12-31 23:02:52 +000037 <script type="text/javascript" src="../fancybox/jquery.fancybox-1.3.4.pack.js"></script>
38 <link rel="stylesheet" type="text/css" href="../fancybox/jquery.fancybox-1.3.4.css" media="screen" />
39 <script type="text/javascript">
40 $(document).ready(function() {
41 $("a[href$=.jpg],a[href$=.png],a[href$=.gif]").fancybox({
42 'transitionIn' : 'elastic',
43 'transitionOut' : 'elastic',
44 'overlayShow' : false,
45 'opacity' : true
46 });
47 });
48 </script>
cristy3eaa0ef2010-03-06 20:35:26 +000049</head>
50
51<body id="www-imagemagick-org">
52<div class="titlebar">
53<a href="../index.html">
54 <img src="../images/script.png" alt="[ImageMagick]"
55 style="width: 350px; height: 60px; margin: 28px auto; float: left;" /></a>
56<a href="http://www.networkredux.com">
57 <img src="../images/networkredux.png" alt="[sponsor]"
cristy52923442011-01-15 22:54:31 +000058 style="margin-top: 42px; border: 0px; float: left;" /></a>
cristy3eaa0ef2010-03-06 20:35:26 +000059<a href="http://www.imagemagick.org/discourse-server/">
cristyaf8d6652011-02-04 21:57:45 +000060 <img src="../images/logo.jpg"
61 alt="ImageMagick Logo"
cristy178edaf2011-01-23 03:42:39 +000062 style="width: 123px; height: 118px; border: 0px; float: right;" /></a>
cristy3eaa0ef2010-03-06 20:35:26 +000063<a href="../index.html">
cristyaf8d6652011-02-04 21:57:45 +000064 <img src="../images/sprite.jpg"
65 alt="ImageMagick Sprite"
cristy3eaa0ef2010-03-06 20:35:26 +000066 style="width: 114px; height: 118px; border: 0px; float: right;" /></a>
67</div>
68
cristyce69bb02010-07-27 19:49:46 +000069<div class="westbar">
cristy3eaa0ef2010-03-06 20:35:26 +000070
cristy3ed852e2009-09-05 21:47:34 +000071<div class="menu">
cristy83a272e2010-05-07 20:40:35 +000072 <a title="About ImageMagick" href="../index.html">About ImageMagick</a>
cristy3ed852e2009-09-05 21:47:34 +000073</div>
cristy3eaa0ef2010-03-06 20:35:26 +000074<div class="sep"></div>
cristy3ed852e2009-09-05 21:47:34 +000075<div class="menu">
cristybb503372010-05-27 20:51:26 +000076 <a title="Binary Releases" href="../www/binary-releases.html">Binary Releases</a>
77</div>
78<div class="sub">
79 <a title="Binary Release: Unix" href="../www/binary-releases.html#unix">Unix</a>
80</div>
81<div class="sub">
82 <a title="Binary Release: MacOS X" href="../www/binary-releases.html#macosx">Mac OS X</a>
83</div>
84<div class="sub">
cristyda16f162011-02-19 23:52:17 +000085 <a title="Binary Release: iPhone" href="../www/binary-releases.html#iPhone">iPhone</a>
86</div>
87<div class="sub">
cristybb503372010-05-27 20:51:26 +000088 <a title="Binary Release: Windows" href="../www/binary-releases.html#windows">Windows</a>
89</div>
90<div class="sep"></div>
91<div class="menu">
cristy83a272e2010-05-07 20:40:35 +000092 <a title="Command-line Tools" href="../www/command-line-tools.html">Command-line Tools</a>
cristy3ed852e2009-09-05 21:47:34 +000093</div>
94<div class="sub">
cristy83a272e2010-05-07 20:40:35 +000095 <a title="Command-line Tools: Processing" href="../www/command-line-processing.html">Processing</a>
cristy3ed852e2009-09-05 21:47:34 +000096</div>
97<div class="sub">
cristy83a272e2010-05-07 20:40:35 +000098 <a title="Command-line Tools: Options" href="../www/command-line-options.html">Options</a>
cristy3ed852e2009-09-05 21:47:34 +000099</div>
100<div class="sub">
cristy83a272e2010-05-07 20:40:35 +0000101 <a title="Command-line Tools: Usage" href="http://www.imagemagick.org/Usage/">Usage</a>
cristy3ed852e2009-09-05 21:47:34 +0000102</div>
103<div class="menu">
cristy83a272e2010-05-07 20:40:35 +0000104 <a title="Program Interfaces" href="../www/api.html">Program Interfaces</a>
cristy3ed852e2009-09-05 21:47:34 +0000105</div>
106<div class="sub">
cristy83a272e2010-05-07 20:40:35 +0000107 <a title="Program Interface: MagickWand" href="../www/magick-wand.html">MagickWand</a>
cristy3ed852e2009-09-05 21:47:34 +0000108</div>
109<div class="sub">
cristy83a272e2010-05-07 20:40:35 +0000110 <a title="Program Interface: MagickCore" href="../www/magick-core.html">MagickCore</a>
cristy3ed852e2009-09-05 21:47:34 +0000111</div>
112<div class="sub">
cristy83a272e2010-05-07 20:40:35 +0000113 <a title="Program Interface: PerlMagick" href="../www/perl-magick.html">PerlMagick</a>
cristy3ed852e2009-09-05 21:47:34 +0000114</div>
115<div class="sub">
cristydcca3fa2010-12-29 21:50:07 +0000116 <a title="Program Interface: Magick++" href="../www/magick++.html">Magick++</a>
cristy3ed852e2009-09-05 21:47:34 +0000117</div>
cristy3eaa0ef2010-03-06 20:35:26 +0000118<div class="sep"></div>
cristy3ed852e2009-09-05 21:47:34 +0000119<div class="menu">
cristy83a272e2010-05-07 20:40:35 +0000120 <a title="Install from Source" href="../www/install-source.html">Install from Source</a>
cristy3ed852e2009-09-05 21:47:34 +0000121</div>
122<div class="sub">
cristy83a272e2010-05-07 20:40:35 +0000123 <a title="Install from Source: Unix" href="../www/install-source.html#unix">Unix</a>
cristy3ed852e2009-09-05 21:47:34 +0000124</div>
125<div class="sub">
cristy83a272e2010-05-07 20:40:35 +0000126 <a title="Install from Source: Windows" href="../www/install-source.html#windows">Windows</a>
cristy3ed852e2009-09-05 21:47:34 +0000127 </div>
128<div class="menu">
cristy83a272e2010-05-07 20:40:35 +0000129 <a title="Resources" href="../www/resources.html">Resources</a>
cristy3ed852e2009-09-05 21:47:34 +0000130</div>
cristybb503372010-05-27 20:51:26 +0000131<div class="menu">
132 <a title="Architecture" href="../www/architecture.html">Architecture</a>
133</div>
cristy3ed852e2009-09-05 21:47:34 +0000134<div class="menu">
cristy83a272e2010-05-07 20:40:35 +0000135 <a title="Download" href="../www/download.html">Download</a>
cristy3ed852e2009-09-05 21:47:34 +0000136</div>
cristy3eaa0ef2010-03-06 20:35:26 +0000137<div class="sep"></div>
cristy3ed852e2009-09-05 21:47:34 +0000138<div class="menu">
cristy52923442011-01-15 22:54:31 +0000139 <a title="Search" href="../www/search.html">Search</a>
cristy3ed852e2009-09-05 21:47:34 +0000140</div>
cristy3eaa0ef2010-03-06 20:35:26 +0000141<div class="sep"></div>
cristy3ed852e2009-09-05 21:47:34 +0000142<div class="menu">
cristyffb69ed2010-12-25 00:06:48 +0000143 <a title="Site Map" href="../www/sitemap.html">Site Map</a>
cristy3ed852e2009-09-05 21:47:34 +0000144</div>
145<div class="sub">
cristyffb69ed2010-12-25 00:06:48 +0000146 <a title="Site Map: Links" href="../www/links.html">Links</a>
cristy3ed852e2009-09-05 21:47:34 +0000147</div>
cristy3eaa0ef2010-03-06 20:35:26 +0000148<div class="sep"></div>
cristy3ed852e2009-09-05 21:47:34 +0000149<div class="menu">
cristy83a272e2010-05-07 20:40:35 +0000150 <a title="Sponsors" href="../www/sponsors.html">Sponsors:</a>
cristy3ed852e2009-09-05 21:47:34 +0000151
152<div class="sponsbox">
cristy178edaf2011-01-23 03:42:39 +0000153<div class="sponsor">
cristyaf8d6652011-02-04 21:57:45 +0000154 <a title="Sponsor: Best Web Hosting" href="http://webhostinggeeks.com">Best Web Hosting</a><!-- 201110010720 -->
155</div>
156<div class="sponsor">
157 <a title="Sponsor: Web Hosting Ratings" href="http://webhostingrating.com">Web Hosting Ratings</a><!-- 201110010720 -->
158</div>
159<div class="sponsor">
cristy2bd2a982011-02-15 00:52:58 +0000160 <a title="Sponsor: Druckerei" href="http://www.allesdruck.de">Druckerei</a><!-- 201107010240 r.leo -->
cristy178edaf2011-01-23 03:42:39 +0000161</div>
cristyec6b4752011-01-08 03:16:23 +0000162<div class="sponsor">
cristy52923442011-01-15 22:54:31 +0000163 <a title="Sponsor: Web Hosting" href="http://www.bodhost.com/hosting.shtml">Web Hosting</a><!-- 201104010090 -->
cristy5c4585b2010-11-11 00:13:57 +0000164</div>
165<div class="sponsor">
cristyc5baf4f2010-08-31 15:05:33 +0000166 <a title="Sponsor: Image Converter" href="http://www.batchphoto.com">Image Converter</a><!-- 201103010900 Bits Coffee-->
167</div>
168<div class="sponsor">
cristy851dbce2010-08-06 21:40:00 +0000169 <a title="Sponsor: Flyer drucken" href="http://www.online-druck.biz">Flyer drucken</a><!-- 201109010900 Floeter-->
170</div>
cristyec6b4752011-01-08 03:16:23 +0000171<div class="sponsor">
cristy178edaf2011-01-23 03:42:39 +0000172 <a title="Sponsor: Druckerei" href="http://print24.com/de/">Druckerei</a><!-- 201110010720 -->
173</div>
174<div class="sponsor">
cristy7b07f442011-02-23 01:28:53 +0000175 <a title="Sponsor: Notebook Reparatur Berlin" href="http://www.notebook-reparaturen-berlin.de">Notebook Reparatur Berlin</a><!-- 2011050100025 gabi.schulze-->
cristyec6b4752011-01-08 03:16:23 +0000176</div>
cristy3ed852e2009-09-05 21:47:34 +0000177</div>
cristyce69bb02010-07-27 19:49:46 +0000178</div>
179</div>
cristy3eaa0ef2010-03-06 20:35:26 +0000180
cristyce69bb02010-07-27 19:49:46 +0000181<div class="eastbar">
182 <script type="text/javascript">
183 <!--
184 google_ad_client = "pub-3129977114552745";
cristyce69bb02010-07-27 19:49:46 +0000185 google_ad_slot = "0574824969";
186 google_ad_width = 160;
187 google_ad_height = 600;
188 //-->
189 </script>
190 <script type="text/javascript"
191 src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
192 </script>
cristy3eaa0ef2010-03-06 20:35:26 +0000193</div>
194
195<div class="main">
196
cristydcca3fa2010-12-29 21:50:07 +0000197<h1>Apply Special Effects to an Image with an Fx Expression</h1>
cristy3ed852e2009-09-05 21:47:34 +0000198<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>
199
cristydcca3fa2010-12-29 21:50:07 +0000200<a id="fx"></a>
cristy3ed852e2009-09-05 21:47:34 +0000201<div class="doc-section">
202
203<p>Use the Fx special effects image operator to apply a mathematical expression to an image or image channels. Use Fx to:</p>
204
205<ul>
206 <li>create canvases, gradients, mathematical colormaps</li>
207 <li>move color values between images and channels</li>
208 <li>translate, flip, mirror, rotate, scale, shear and generally distort images</li>
209 <li>merge or composite multiple images together</li>
210 <li>convolve or merge neighboring pixels together</li>
211 <li>generate image metrics or 'fingerprints'</li>
212</ul>
213
214<p>The expression can be simple:</p>
215
216<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>
217<p>Here, we convert a black to a navy blue image:</p>
218
219<p class="image">
220 <a href="../images/black.png"><img src="../images/black.png" width="64" height="64" alt="black" /></a>
221 <img style="margin-top:22px; margin-bottom:22px;" src="../images/right.gif" width="20" height="20" alt="==>" />
222 <a href="../images/navy.png"><img src="../images/navy.png" width="64" height="64" alt="navy" /></a>
223</p>
224
225<p>Or the expression can be complex:</p>
226
227<p class='crt'><span class="crtprompt"> $magick&gt; </span><span class='crtin'>convert rose.jpg \ <br/>
228 -fx "(1.0/(1.0+exp(10.0*(0.5-u)))-0.006693)*1.0092503" \ <br/>
229 rose-sigmoidal.png</span></p>
230<p>This expression results in a high contrast version of the image:</p>
231
232<p class="image">
233 <a href="../images/rose.jpg"><img src="../images/rose.jpg" width="70" height="46" alt="rose" /></a>
234 <img style="margin-top:13px; margin-bottom:13px;" src="../images/right.gif" width="20" height="20" alt="==>" />
235 <a href="../images/rose-sigmoidal.png"><img src="../images/rose-sigmoidal.png" width="70" height="46" alt="rose-sigmoidal" /></a>
236</p>
237
238<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>
239
240<p class='crt'><span class="crtprompt"> $magick&gt; </span><span class='crtin'>convert -size 70x70 xc: \ <br/>
241 -fx "Xi=i-w/2; Yj=j-h/2; 1.2*(0.5-hypot(Xi,Yj)/70.0)+0.5" \ <br/>
242 radial-gradient.png</span></p>
243<p>The command above returns this image:</p>
244
245<p class="image">
246 <a href="../images/radial-gradient.png"><img src="../images/radial-gradient.png" width="70" height="70" alt="radial-gradient" /></a>
247</p>
248<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>
249
250<p>The next section discusses the Fx expression language.</p>
251
252</div>
253
cristydcca3fa2010-12-29 21:50:07 +0000254<h2><a id="anatomy"></a>The Anatomy of an Fx Expression</h2>
cristy3ed852e2009-09-05 21:47:34 +0000255<div class="doc-section">
256
257<h3>The Fx Expression Language</h3>
258<div class="doc-section">
259
260<p>The formal Fx expression language is defined here:</p>
261
262<dl class="doc">
263 <dt class="doc"> numbers:</dt>
264 <dd> integer, floating point, or scientfic notation (+/- required, e.g. 3.81469e-06)</dd>
265 <dt class="doc"> constants: </dt>
266 <dd> e, Epsilon, QuantumRange, QuantumScale, Opaque, Pi, Transparent</dd>
267 <dt class="doc"> Fx operators (in order of precedence): </dt>
cristyd92fed52010-10-25 13:48:19 +0000268 <dd> ^ (power), unary -, *, /, % (modulo), +, -,
cristy3ed852e2009-09-05 21:47:34 +0000269 &lt;&lt;, &gt;&gt;, &lt;, &lt;=, &gt;, &gt;=, ==, !=,
270 &amp; (bitwise AND), | (bitwise OR),
271 &amp;&amp; (logical AND), || (logical OR),
272 ~ (logical NOT), ?: (ternary conditional)</dd>
273 <dt class="doc"> math functions: </dt>
cristy19156992010-03-04 17:04:59 +0000274 <dd> abs(), acos(), airy(), alt(), asin(), atan(), atan2(), ceil(), cos(), cosh(), debug(), exp(), floor(),
275 hypot(), int(), j0(), j1(), jinc(), ln(), log(), logtwo(), max(), min(), mod(), pow(), rand(), round(),
cristy3c98a4f2010-08-13 20:09:41 +0000276 sign(), sin(), sinc(), sinh(), sqrt(), tan(), tanh(), trunc()</dd>
cristy3ed852e2009-09-05 21:47:34 +0000277 <dt class="doc"> channel functions: </dt>
278 <dd> channel(r,g,b,a), channel(c,m,y,k,a)</dd>
279 <dt class="doc"> color names:</dt>
280 <dd> red, cyan, black, etc.</dd>
281 <dt class="doc"> color functions:</dt>
282 <dd> rgb(), rgba(), cmyk(), cmyka(), hsl(), hsla()</dd>
283 <dt class="doc"> color hex values:</dt>
284 <dd> #ccc, #cbfed0, #b9e1cc00</dd>
285 <dt class="doc"> symbols:</dt>
286 <dd style="white-space:pre">
287 s = current image in sequence
288 t = scene number of current image in sequence
289 u = first image in sequence
290 v = second image in sequence
291 n = number of images in sequence
292
293 i = column offset
294 j = row offset
295 p = pixel to use (absolute or relative to current pixel)
296
297 w = width of this image
298 h = height of this image
299 z = channel depth
300
301 r = red value (from RGBA), of a specific or current pixel
302 g = green ''
303 b = blue ''
304 a = alpha ''
305 o = opacity ''
306
307 c = cyan value of CMYK color of pixel
308 y = yellow ''
309 m = magenta ''
310 k = black ''
311
312 intensity = pixel intensity
313
314 hue = pixel hue
315 saturation = pixel saturation
316 lightness = pixel lightness
317 luminance = pixel luminance
318
319 page.width = page width
320 page.height = page height
321 page.x = page x offset
322 page.y = page y offset
323
324 resolution.x = x resolution
325 resolution.y = y resolution
326
327 depth = image depth
328 minima = image minima
329 maxima = image maxima
330 mean = image mean
331 standard_deviation = image standard deviation
332 kurtosis = image kurtosis
333 skewness = image skewness
334 (add a channel specifier to compute a statistic for that channel, e.g. depth.r)
335 </dd>
336</dl>
337
338</div>
339
340<h3>The Fx Expression</h3>
341<div class="doc-section">
342
343<p>An Fx expression may include any combination of the following:</p>
344<ul>
345<li> <em>x</em> <kbd>^</kbd> <em>y</em>: exponentiation (<em>x<sup>y</sup></em>)</li>
346<li> <kbd>(</kbd> ... <kbd>)</kbd>: grouping</li>
347<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>
348<li> <em>x</em> <kbd>/</kbd> <em>y</em>: division</li>
349<li> <em>x</em> <kbd>%</kbd> <em>y</em>: modulo</li>
350<li> <em>x</em> <kbd>+</kbd> <em>y</em>: addition</li>
351<li> <em>x</em> <kbd>-</kbd> <em>y</em>: subtraction</li>
352<li> <em>x</em> <kbd>&lt;&lt;</kbd> <em>y</em>: left shift</li>
353<li> <em>x</em> <kbd>&gt;&gt;</kbd> <em>y</em>: right shift</li>
354<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>
355<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>
356<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>
357<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>
358<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>
359<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>
360<li> <em>x</em> <kbd>&amp;</kbd> <em>y</em>: binary AND</li>
361<li> <em>x</em> <kbd>|</kbd> <em>y</em>: binary OR</li>
362<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>
363<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>
364<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>
365<li> <kbd>+</kbd><em>x</em>: unary plus, return 1.0*value</li>
366<li> <kbd>-</kbd><em>x</em>: unary minus, return -1.0*value</li>
367<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>
368<li> <em>x</em> <kbd>=</kbd> <em>y</em>: assignment; assignment variables are restricted to letter combinations only (e.g. Xi not X1)</li>
369<li> <em>x</em> <kbd>;</kbd> <em>y</em>: statement separator </li>
370<li> <kbd>pi</kbd>: constant (3.141659...)</li>
371<li> <kbd>e</kbd>: constant (2.71828...)</li>
372<li> <kbd>QuantumRange</kbd>: constant maximum pixel value (255 for Q8, 65535 for Q16)</li>
373<li> <kbd>QuantumScale</kbd>: constant 1.0/<kbd>QuantumRange</kbd></li>
374<li> <kbd>intensity</kbd>: pixel intensity; equivalent to 0.299*red+0.587*green+0.114*blue</li>
375<li> <kbd>hue</kbd>: pixel hue</li>
376<li> <kbd>saturation</kbd>: pixel saturation</li>
377<li> <kbd>lightness</kbd>: pixel lightness; equivalent to 0.5*max(red,green,blue) + 0.5*min(red,green,blue)</li>
378<li> <kbd>luminance</kbd>: pixel luminance; equivalent to 0.2126*red + 0.7152*green + 0.0722*blue</li>
379<li> <kbd>red, green, blue</kbd>, etc.: color names</li>
380<li> <kbd>#ccc, #cbfed0, #b9e1cc00</kbd>, etc.: color hex values</li>
381<li> <kbd>rgb(), rgba(), cmyk(), cmyka(), hsl(), hsla()</kbd>: color functions</li>
382<li> <kbd>s, t, u, v, n, i, j, w, h, z, r, g, b, a, o, c, y, m, k</kbd>: symbols</li>
383<li> <kbd>abs(</kbd><em>x</em><kbd>)</kbd>: absolute value function</li>
384<li> <kbd>acos(</kbd><em>x</em><kbd>)</kbd>: arc cosine function</li>
cristy2c839602010-04-03 02:32:08 +0000385<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 +0000386<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>
387<li> <kbd>asin(</kbd><em>x</em><kbd>)</kbd>: arc sine function</li>
388<li> <kbd>atan(</kbd><em>x</em><kbd>)</kbd>: arc tangent function</li>
389<li> <kbd>atan2(</kbd><em>y</em>,<em>x</em><kbd>)</kbd>: arc tangent function of two variables</li>
390<li> <kbd>ceil(</kbd><em>x</em><kbd>)</kbd>: smallest integral value not less than argument</li>
391<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>
392<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>
393<li> <kbd>cos(</kbd><em>x</em><kbd>)</kbd>: cosine function</li>
394<li> <kbd>cosh(</kbd><em>x</em><kbd>)</kbd>: hyperbolic cosine function</li>
395<li> <kbd>debug(</kbd><em>x</em><kbd>)</kbd>: print <em>x</em> (useful for debugging your expression)</li>
396<li> <kbd>exp(</kbd><em>x</em><kbd>)</kbd>: natural exponential function (<em>e<sup>x</sup></em>)</li>
397<li> <kbd>floor(</kbd><em>x</em><kbd>)</kbd>: largest integral value not greater than argument</li>
398<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>
399<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 +0000400<li> <kbd>j0(</kbd><em>x</em><kbd>)</kbd>: Bessel functions of <em>x</em> of the first kind of order 0</li>
401<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 +0000402<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 +0000403<li> <kbd>ln(</kbd><em>x</em><kbd>)</kbd>: natural logarithm function</li>
404<li> <kbd>log(</kbd><em>x</em><kbd>)</kbd>: logarithm base 10</li>
405<li> <kbd>logtwo(</kbd><em>x</em><kbd>)</kbd>: logarithm base 2</li>
406<li> <kbd>ln(</kbd><em>x</em><kbd>)</kbd>: natural logarithm</li>
407<li> <kbd>max(</kbd><em>x</em>, <em>y</em><kbd>)</kbd>: maximum of <em>x</em> and <em>y</em></li>
408<li> <kbd>min(</kbd><em>x</em>, <em>y</em><kbd>)</kbd>: minimum of <em>x</em> and <em>y</em></li>
409<li> <kbd>mod(</kbd><em>x</em>, <em>y</em><kbd>)</kbd>: floating-point remainder function</li>
410<li> <kbd>pow(</kbd><em>x</em>,<em>y</em><kbd>)</kbd>: power function (<em>x<sup>y</sup></em>)</li>
411<li> <kbd>rand()</kbd>: value uniformly distributed over the interval [0.0, 1.0) with a 2 to the 128th-1 period</li>
412<li> <kbd>round()</kbd>: round to integral value, regardless of rounding direction</li>
413<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>
414<li> <kbd>sin(</kbd><em>x</em><kbd>)</kbd>: sine function</li>
cristy2c2a4492010-03-16 15:06:03 +0000415<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 +0000416<li> <kbd>sinh(</kbd><em>x</em><kbd>)</kbd>: hyperbolic sine function</li>
417<li> <kbd>sqrt(</kbd><em>x</em><kbd>)</kbd>: square root function</li>
418<li> <kbd>tan(</kbd><em>x</em><kbd>)</kbd>: tangent function</li>
419<li> <kbd>tanh(</kbd><em>x</em><kbd>)</kbd>: hyperbolic tangent function</li>
cristy3c98a4f2010-08-13 20:09:41 +0000420<li> <kbd>trunc(</kbd><em>x</em><kbd>)</kbd>: round to integer, towards zero</li>
cristy3ed852e2009-09-05 21:47:34 +0000421</ul>
422
423<p>The expression semantics include these rules:</p>
424
425<ul>
426<li>symbols are case insensitive</li>
427<li>only one ternary conditional (e.g. x ? y : z) per statement</li>
428<li>statements are assignments or the final expression to return</li>
429<li>an assignment starts a statement, it is not an operator</li>
430<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>
cristyb7b531e2010-10-24 01:41:05 +0000431<li>Unary operators have a lower priority than binary operators, that is, the unary minus (negation) has lower precedence than exponentiation, so -3^2 is interpreted as -(3^2) = -9. Use parentheses to clarify your intent (e.g. (-3)^2 = 9).</li>
cristyce66ab12010-10-21 23:36:32 +0000432<li>Similarly, care must be exercised when using the slash ('/') symbol. The string of characters <em>1/2x</em> is interpreted as (1/2)x. The contrary interpretation should be written explicitly as 1/(2x). Again, the use of parentheses helps clarify the meaning and should be used whenever there is any chance of misinterpretation.</li>
cristy3ed852e2009-09-05 21:47:34 +0000433</ul>
434
cristyce66ab12010-10-21 23:36:32 +0000435
cristy3ed852e2009-09-05 21:47:34 +0000436</div>
437
438<h3>Source Images</h3>
439<div class="doc-section">
440
441<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>
442
443<p>As an example, we form an image by averaging the first image and third images:</p>
444
445<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>
446<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>
447
cristy19156992010-03-04 17:04:59 +0000448<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 +0000449
450<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>
451<div class="image">
cristy3ed852e2009-09-05 21:47:34 +0000452 <a href="../images/logo-sm-flop.png"><img src="../images/logo-sm-flop.png" width="128" height="96" alt="logo-sm-flop.png" /></a>
453 <a href="../images/logo-sm.png"><img src="../images/logo-sm.png" width="128" height="96" alt="logo-sm.png" /></a>
454<img style="margin-top:38px; margin-bottom:38px;" src="../images/right.gif" width="20" height="20" alt="==>" />
455 <a href="../images/logo-sm-fx.png"><img src="../images/logo-sm-fx.png" width="128" height="96" alt="logo-sm-fx.png" /></a>
cristy3ed852e2009-09-05 21:47:34 +0000456</div>
457
458
459</div>
460
461<h3>Accessing Pixels</h3>
462<div class="doc-section">
463
464<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>
465
466<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>
467
468<pre class="text">
469 p[-1].g green value of pixel to the immediate left of the current pixel
470 p[-1,-1].r red value of the pixel diagonally left and up from current pixel
471</pre>
472
473<p>To specify an absolute position, use braces, rather than brackets.</p>
474
475<pre class="text">
476 p{0,0}.r red value of the pixel in the upper left corner of the image
477 p{12,34}.b blue pixel value at column number 12, row 34 of the image
478</pre>
479
480<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>
481
482<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>
483
484</div>
485
486<h3>Apply an Expression to Select Image Channels</h3>
487<div class="doc-section">
488
489<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>
490
491<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>
492</div>
493
494<h3>Results</h3>
495<div class="doc-section">
496
497<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>
498
499<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>
500
501
502<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>
503
504<p class='crt'><span class="crtprompt"> $magick&gt; </span><span class='crtin'>convert xc:'rgb(25%,50%,75%)' rose: -colorspace rgb \ <br/>
505 -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/>
506 Red channel of NW corner of image # 1 is 0.188235</span></p>
507<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>
508
509</div>
510</div>
cristy3eaa0ef2010-03-06 20:35:26 +0000511
512</div>
513
514<div id="linkbar">
cristyce69bb02010-07-27 19:49:46 +0000515 <span id="linkbar-west">&nbsp;</span>
cristy3eaa0ef2010-03-06 20:35:26 +0000516 <span id="linkbar-center">
517 <a href="http://www.imagemagick.org/discourse-server/">Discourse Server</a> &bull;
cristya8902942010-07-30 00:49:52 +0000518 <a href="http://www.imagemagick.org/MagickStudio/scripts/MagickStudio.cgi">Studio</a>
cristy3eaa0ef2010-03-06 20:35:26 +0000519 </span>
520 <span id="linkbar-east">&nbsp;</span>
521 </div>
522 <div class="footer">
cristy7e41fe82010-12-04 23:12:08 +0000523 <span id="footer-west">&copy; 1999-2011 ImageMagick Studio LLC</span>
cristy3eaa0ef2010-03-06 20:35:26 +0000524 <span id="footer-east"> <a href="http://www.imagemagick.org/script/contact.php">Contact the Wizards</a></span>
525 </div>
526 <div style="clear: both; margin: 0; width: 100%; "></div>
cristya8902942010-07-30 00:49:52 +0000527 <script type="text/javascript">
528 var _gaq = _gaq || [];
529 _gaq.push(['_setAccount', 'UA-17690367-1']);
530 _gaq.push(['_trackPageview']);
531
532 (function() {
533 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
534 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
535 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
536 })();
537 </script>
cristy3eaa0ef2010-03-06 20:35:26 +0000538</body>
539</html>