Debian Codegraph @

www/fx.html

raw symbols ◀ ▶
Source reconstructed at patch state 2 of 4 — not the installed (fully patched) source.
4 Debian patches touch this file
1
2
3
4 <!DOCTYPE html>
5 <html lang="en" data-bs-theme="dark">
6 <head>
7 <script src="assets/color-modes.js" ></script>
8 <meta charset="utf-8" />
9 <meta name="viewport" content="width=device-width, initial-scale=1" />
10 <title>ImageMagick – The FX Special Effects Image Operator</title>
11 <meta name="keywords" content="The FX Special Effects Image Operator, Image Processing, Digital Image Editing, Image Conversion, Open-Source Software, Image Manipulation, Command-Line Image Tools" />
12 <meta name="description" content="ImageMagick is a powerful, open-source software suite for creating, editing, converting, and manipulating images in over 200 formats. Ideal for web developers, graphic designers, and researchers, it offers versatile tools for image processing, including batch processing, format conversion, and complex image transformations." />
13 <meta name="application-name" content="ImageMagick" />
14 <meta name="application-url" content="https://imagemagick.org" />
15 <meta name="copyright" content="Copyright (c) 1999 ImageMagick Studio LLC" />
16 <meta itemprop='url' content='../' />
17 <meta itemprop='title' content='ImageMagick' />
18 <meta itemprop='description' content="ImageMagick is a powerful, open-source software suite for creating, editing, converting, and manipulating images in over 200 formats. Ideal for web developers, graphic designers, and researchers, it offers versatile tools for image processing, including batch processing, format conversion, and complex image transformations." />
19 <meta property='og:url' content='../' />
20 <meta property='og:name' content='ImageMagick' />
21 <meta property='og:image' content='../images/logo.png' />
22 <meta property='og:type' content='website' />
23 <meta property='og:site_name' content='ImageMagick' />
24 <meta property='og:description' content="ImageMagick is a powerful, open-source software suite for creating, editing, converting, and manipulating images in over 200 formats. Ideal for web developers, graphic designers, and researchers, it offers versatile tools for image processing, including batch processing, format conversion, and complex image transformations." />
25 <meta name="google-site-verification" content="_bMOCDpkx9ZAzBwb2kF3PRHbfUUdFj2uO8Jd1AXArz4" />
26 <link type="images/png" sizes="64x64" href="../images/wand.png" rel="icon" />
27 <link type="images/icon" sizes="16x16" href="../images/wand.ico" rel="shortcut icon" />
28 <link href="fx.html" rel="canonical" />
29 <link href="assets/bootstrap.min.css" rel="stylesheet" />
30 </head>
31 <body>
32 <svg xmlns="http://www.w3.org/2000/svg" class="d-none">
33 <symbol id="check2" viewBox="0 0 16 16">
34 <path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"/>
35 </symbol>
36 <symbol id="circle-half" viewBox="0 0 16 16">
37 <path d="M8 15A7 7 0 1 0 8 1v14zm0 1A8 8 0 1 1 8 0a8 8 0 0 1 0 16z"/>
38 </symbol>
39 <symbol id="moon-stars-fill" viewBox="0 0 16 16">
40 <path d="M6 .278a.768.768 0 0 1 .08.858 7.208 7.208 0 0 0-.878 3.46c0 4.021 3.278 7.277 7.318 7.277.527 0 1.04-.055 1.533-.16a.787.787 0 0 1 .81.316.733.733 0 0 1-.031.893A8.349 8.349 0 0 1 8.344 16C3.734 16 0 12.286 0 7.71 0 4.266 2.114 1.312 5.124.06A.752.752 0 0 1 6 .278z"/>
41 <path d="M10.794 3.148a.217.217 0 0 1 .412 0l.387 1.162c.173.518.579.924 1.097 1.097l1.162.387a.217.217 0 0 1 0 .412l-1.162.387a1.734 1.734 0 0 0-1.097 1.097l-.387 1.162a.217.217 0 0 1-.412 0l-.387-1.162A1.734 1.734 0 0 0 9.31 6.593l-1.162-.387a.217.217 0 0 1 0-.412l1.162-.387a1.734 1.734 0 0 0 1.097-1.097l.387-1.162zM13.863.099a.145.145 0 0 1 .274 0l.258.774c.115.346.386.617.732.732l.774.258a.145.145 0 0 1 0 .274l-.774.258a1.156 1.156 0 0 0-.732.732l-.258.774a.145.145 0 0 1-.274 0l-.258-.774a1.156 1.156 0 0 0-.732-.732l-.774-.258a.145.145 0 0 1 0-.274l.774-.258c.346-.115.617-.386.732-.732L13.863.1z"/>
42 </symbol>
43 <symbol id="sun-fill" viewBox="0 0 16 16">
44 <path d="M8 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0zm0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13zm8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5zM3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8zm10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0zm-9.193 9.193a.5.5 0 0 1 0 .707L3.05 13.657a.5.5 0 0 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0zm9.193 2.121a.5.5 0 0 1-.707 0l-1.414-1.414a.5.5 0 0 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707zM4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .708z"/>
45 </symbol>
46 </svg>
47 <div class="dropdown position-fixed bottom-0 end-0 mb-3 me-3 bd-mode-toggle">
48 <button class="btn btn-bd-secondary py-2 dropdown-toggle d-flex align-items-center"
49 id="bd-theme"
50 type="button"
51 aria-expanded="false"
52 data-bs-toggle="dropdown"
53 aria-label="Toggle theme (auto)">
54 <svg class="bi my-1 theme-icon-active" width="1em" height="1em"><use href="#circle-half"></use></svg>
55 <span class="visually-hidden" id="bd-theme-text">Toggle theme</span>
56 </button>
57 <ul class="dropdown-menu dropdown-menu-end shadow" aria-labelledby="bd-theme-text">
58 <li>
59 <button type="button" class="dropdown-item d-flex align-items-center" data-bs-theme-value="light" aria-pressed="false">
60 <svg class="bi me-2 opacity-50" width="1em" height="1em"><use href="#sun-fill"></use></svg>
61 Light
62 <svg class="bi ms-auto d-none" width="1em" height="1em"><use href="#check2"></use></svg>
63 </button>
64 </li>
65 <li>
66 <button type="button" class="dropdown-item d-flex align-items-center active" data-bs-theme-value="dark" aria-pressed="false">
67 <svg class="bi me-2 opacity-50" width="1em" height="1em"><use href="#moon-stars-fill"></use></svg>
68 Dark
69 <svg class="bi ms-auto d-none" width="1em" height="1em"><use href="#check2"></use></svg>
70 </button>
71 </li>
72 <li>
73 <button type="button" class="dropdown-item d-flex align-items-center" data-bs-theme-value="auto" aria-pressed="true">
74 <svg class="bi me-2 opacity-50" width="1em" height="1em"><use href="#circle-half"></use></svg>
75 Auto
76 <svg class="bi ms-auto d-none" width="1em" height="1em"><use href="#check2"></use></svg>
77 </button>
78 </li>
79 </ul>
80 </div>
81 <svg xmlns="http://www.w3.org/2000/svg" class="d-none">
82 <symbol id="arrow-right-circle" viewBox="0 0 16 16">
83 <path d="M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0zM4.5 7.5a.5.5 0 0 0 0 1h5.793l-2.147 2.146a.5.5 0 0 0 .708.708l3-3a.5.5 0 0 0 0-.708l-3-3a.5.5 0 1 0-.708.708L10.293 7.5H4.5z"/>
84 </symbol>
85 <symbol id="color-mode" viewBox="0 0 118 94">
86 <title>Color Modes</title>
87 <path fill-rule="evenodd" clip-rule="evenodd" d="M24.509 0c-6.733 0-11.715 5.893-11.492 12.284.214 6.14-.064 14.092-2.066 20.577C8.943 39.365 5.547 43.485 0 44.014v5.972c5.547.529 8.943 4.649 10.951 11.153 2.002 6.485 2.28 14.437 2.066 20.577C12.794 88.106 17.776 94 24.51 94H93.5c6.733 0 11.714-5.893 11.491-12.284-.214-6.14.064-14.092 2.066-20.577 2.009-6.504 5.396-10.624 10.943-11.153v-5.972c-5.547-.529-8.934-4.649-10.943-11.153-2.002-6.484-2.28-14.437-2.066-20.577C105.214 5.894 100.233 0 93.5 0H24.508zM80 57.863C80 66.663 73.436 72 62.543 72H44a2 2 0 01-2-2V24a2 2 0 012-2h18.437c9.083 0 15.044 4.92 15.044 12.474 0 5.302-4.01 10.049-9.119 10.88v.277C75.317 46.394 80 51.21 80 57.863zM60.521 28.34H49.948v14.934h8.905c6.884 0 10.68-2.772 10.68-7.727 0-4.643-3.264-7.207-9.012-7.207zM49.948 49.2v16.458H60.91c7.167 0 10.964-2.876 10.964-8.281 0-5.406-3.903-8.178-11.425-8.178H49.948z"></path>
88 </symbol>
89 </svg>
90 <nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
91 <div class="container-fluid">
92 <a class="navbar-brand" href="../index.html"><img class="d-block" id="icon" alt="ImageMagick" width="32" height="32" src="../images/wand.ico"/></a>
93 <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#magick-navbars" aria-controls="magick-navbars" aria-expanded="false" aria-label="Toggle navigation">
94 <span class="navbar-toggler-icon"></span>
95 </button>
96
97 <div class="collapse navbar-collapse" id="magick-navbars">
98 <ul class="navbar-nav me-auto mb-2 mb-md-0">
99 <li class="nav-item">
100 <a class="nav-link " href="download.html">Download</a>
101 </li>
102 <li class="nav-item">
103 <a class="nav-link " href="command-line-tools.html">Tools</a>
104 </li>
105 <li class="nav-item">
106 <a class="nav-link " href="command-line-processing.html">CLI</a>
107 </li>
108 <li class="nav-item">
109 <a class="nav-link " href="develop.html">Develop</a>
110 </li>
111 <li class="nav-item">
112 <a class="nav-link" rel="noopener" target="_blank" href="https://github.com/ImageMagick/ImageMagick/discussions">Community</a>
113 </li>
114 <li class="nav-item">
115 <iframe src="https://github.com/sponsors/ImageMagick/button" title="Sponsor ImageMagick" height="35" width="107" style="border: 0;"></iframe>
116 </li>
117 </ul>
118 <form class="d-flex form-inline" action="search.html">
119 <input class="form-control me-2" type="text" name="q" placeholder="Search" aria-label="Search">
120 <button class="btn btn-outline-success" type="submit" name="sa">Search</button>
121 </form>
122 </div>
123 </div>
124 </nav>
125
126 <div class="col-lg-8 mx-auto p-4 py-md-5 text-body-secondary">
127 <header class="d-flex align-items-center pb-3 mb-5 border-bottom">
128 <a href="../index.html" class="d-flex align-items-center text-decoration-none">
129 <h1 class="mt-5 fs-4">The FX Special Effects Image Operator</h1>
130 </a>
131 </header>
132
133 <main class="container">
134 <div>
135 <p class="text-center"><a href="#fx">The FX Special Effects Image Operator</a> • <a href="#anatomy">The Anatomy of an FX Expression</a></p>
136
137 <a class="anchor" id="fx"></a>
138
139 <p class="lead">The <a href="http://im.snibgo.com/fxnew.htm" rel="noopener" target="_blank">FX special effects image operator</a> applies a mathematical expression to each pixel channel of an image. The FX expression language provides a powerful and flexible way to manipulate images, allowing you to perform a wide range of operations and transformations on your images. Use FX to:</p>
140
141 <ul>
142 <li>create canvases, gradients, mathematical colormaps</li>
143 <li>move color values between images and channels</li>
144 <li>translate, flip, mirror, rotate, scale, shear and generally distort images</li>
145 <li>merge or composite multiple images together</li>
146 <li>convolve or merge neighboring pixels together</li>
147 <li>generate image metrics or 'fingerprints'</li>
148 </ul>
149
150 <p>The operator loops through all the pixels of an image and all the channels of each pixel and returns a new image with the results. The expression can reference any image in the image sequence, but only a copy of the first image is returned with suitable updates per your expression.</p>
151
152 <p>The expression can be simple:</p>
153
154 <pre class="p-3 mb-2 text-body-secondary bg-body-tertiary cli"><samp>magick -size 64x64 canvas:black -channel blue -fx "1/2" fx_navy.png
155 </samp></pre>
156
157 <p>Here, we convert a black to a navy blue image:</p>
158
159 <ul>
160 <a href="../images/black.png"><img src="../images/black.png" width="64" height="64" alt="black" /></a>
161 <img style="margin-top:22px; margin-bottom:22px;" src="../images/right.gif" width="20" height="20" alt="==>" />
162 <a href="../images/navy.png"><img src="../images/navy.png" width="64" height="64" alt="navy" /></a>
163 </ul>
164
165 <p>Or the expression can be complex:</p>
166
167 <pre class="p-3 mb-2 text-body-secondary bg-body-tertiary cli"><samp>magick rose: \
168 -fx "(1.0/(1.0+exp(10.0*(0.5-u)))-0.006693)*1.0092503" \
169 rose-sigmoidal.png
170 </samp></pre>
171
172 <p>This expression results in a high contrast version of the source image:</p>
173
174 <ul>
175 <a href="../images/rose.jpg"><img src="../images/rose.jpg" width="70" height="46" alt="rose" /></a>
176 <img style="margin-top:13px; margin-bottom:13px;" src="../images/right.gif" width="20" height="20" alt="==>" />
177 <a href="../images/rose-sigmoidal.png"><img src="../images/rose-sigmoidal.png" width="70" height="46" alt="rose-sigmoidal" /></a>
178 </ul>
179
180 <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>
181
182 <pre class="p-3 mb-2 text-body-secondary bg-body-tertiary cli"><samp>magick -size 70x70 canvas: \
183 -fx "Xi=i-w/2; Yj=j-h/2; 1.2*(0.5-hypot(Xi,Yj)/70.0)+0.5" \
184 radial-gradient.png
185 </samp></pre>
186
187 <p>The command above returns this image:</p>
188
189 <ul>
190 <a href="../images/radial-gradient.png"><img src="../images/radial-gradient.png" width="70" height="70" alt="radial-gradient" /></a>
191 </ul>
192
193 <p>This FX expression adds random noise to an image:</p>
194
195 <pre class="p-3 mb-2 text-body-secondary bg-body-tertiary cli"><samp>magick photo.jpg -fx 'iso=32; rone=rand(); rtwo=rand(); \
196 myn=sqrt(-2*ln(rone))*cos(2*Pi*rtwo); myntwo=sqrt(-2*ln(rtwo))* \
197 cos(2*Pi*rone); pnoise=sqrt(p)*myn*sqrt(iso)* \
198 channel(4.28,3.86,6.68)/255; max(0,p+pnoise)' noisy.png
199 </samp></pre>
200
201 <p>This FX script utilizes a loop to create a <a href="https://en.wikipedia.org/wiki/Julia_set">Julia set</a>:</p>
202
203 <pre class="p-3 mb-2 text-body-secondary bg-body-tertiary cli"><samp>magick -size 400x400 xc:gray -fx " \
204 Xi=2.4*i/w-1.2; \
205 Yj=2.4*j/h-1.2; \
206 for (pixel=0.0, (hypot(Xi,Yj) &lt; 2.0) &amp;&amp; (pixel &lt; 1.0), \
207 delta=Xi^2-Yj^2; \
208 Yj=2.0*Xi*Yj+0.2; \
209 Xi=delta+0.4; \
210 pixel+=0.00390625 \
211 ); \
212 pixel == 1.0 ? 0.0 : pixel" \
213 \( -size 1x1 xc:white xc:red xc:orange xc:yellow xc:green1 xc:cyan xc:blue \
214 xc:blueviolet xc:white -reverse +append -filter Cubic -resize 1024x1! \) \
215 -clut -rotate -90 julia-set.png</samp></pre>
216
217 <ul>
218 <a href="../images/julia-set.png"><img src="../images/julia-set.png" width="160" height="160" alt="Julia Fractals" /></a>
219 </ul>
220
221 <p>This FX script prints the first 10 prime numbers:</p>
222 <pre class="p-3 mb-2 text-body-secondary bg-body-tertiary cli"><samp>magick xc:gray -fx " \
223 for (prime=2, prime &lt; 30, composite=0; \
224 for (nn=2, nn &lt; (prime/2+1), if ((prime % nn) == 0, composite++, ); nn++); \
225 if (composite &lt;= 0, debug(prime), ); prime++)" null:</samp></pre>
226
227 <p>See <a href="https://usage.imagemagick.org/transform/index.html#fx#fx">Using FX, The Special Effects Image Operator</a> for more examples.</p>
228
229 <p>The <samp>-fx</samp> option replaces any image sequence with a clone of the first image updated with the results of the expression. If you prefer to apply the expression to each image in the sequence, use <samp>+fx</samp> instead.</p>
230
231 <p>The FX expression is interpreted in a single-thread, however, it is executed in multiple threads unless the expression includes the <code>debug()</code> function.</p>
232
233 <p>The next section discusses the FX expression language.</p>
234
235 <h2><a class="anchor" id="anatomy"></a>The Anatomy of an FX Expression</h2>
236
237 <h4>The FX Expression Language</h4>
238
239 <p>The formal FX expression language is defined here:</p>
240
241 <dl class="row">
242 <dt class="col-md-4"> numbers:</dt>
243 <dd class="col-md-8"> integer, floating point, scientific notation (+/- required, e.g. 3.81469e-06), International System number postfixes (.e.g KB, Mib, GB, etc.)</dd>
244 <dt class="col-md-4"> constants: </dt>
245 <dd class="col-md-8"> E (Euler's number), Epsilon, Opaque, Phi (golden ratio), Pi, QuantumRange, QuantumScale, Transparent</dd>
246 <dt class="col-md-4"> FX operators (in order of precedence): </dt>
247 <dd class="col-md-8"> ^ (power), unary -, *, /, % (modulo), +, -,
248 &lt;&lt;, &gt;&gt;, &lt;, &lt;=, &gt;, &gt;=, +=, -=, *=, /=, %=, &lt;&lt;=
249 , &gt;&gt;=,
250 &amp;=, |=, ++, --, ==, !=, &amp; (bitwise AND), | (bitwise OR),
251 &amp;&amp; (logical AND), || (logical OR),
252 ~ (logical NOT), ?: (ternary conditional)</dd>
253 <dt class="col-md-4"> array: </dt>
254 <dd class="col-md-8">an image offers array storage (e.g. p[-1,-1].r) bounded by its width and height. An image sequence represents multiple arrays (e.g. u.p[0,0].r, v.p[0,0].r). Storage is limited to Quantum values, e.g. [0..65535] for Q16 builds and floating point for HDRI-enabled builds.</dd>
255 <dt class="col-md-4"> math functions: </dt>
256 <dd class="col-md-8"> abs(), acos(), acosh(), airy(), alt(), asin(), asinh(), atan(), atanh(), atan2(), ceil(), clamp(), cos(), cosh(), debug(), drc(), erf(), exp(), floor(), gauss(), gcd(), hypot(), int(), isnan(), j0(), j1(), jinc(), ln(), log(), logtwo(), max(), min(), mod(), not(), pow(), rand(), round(), sign(), sin(), sinc(), sinh(), sqrt(), squish(), tan(), tanh(), trunc()</dd>
257 <dt class="col-md-4"> channel functions: </dt>
258 <dd class="col-md-8"> define up to 5 pixel channels</dd>
259 <dt class="col-md-4"> color names:</dt>
260 <dd class="col-md-8"> red, cyan, black, etc.</dd>
261 <dt class="col-md-4"> color functions:</dt>
262 <dd class="col-md-8"> srgb(), srgba(), rgb(), rgba(), cmyk(), cmyka(), hsl(), hsla(), etc.</dd>
263 <dt class="col-md-4"> color hex values:</dt>
264 <dd class="col-md-8"> #ccc, #cbfed0, #b9e1cc00, etc.</dd>
265 <dt class="col-md-4"> symbols:</dt><dd class="col-md-8"><dl>
266 <dd><samp>u</samp>: first image in list</dd>
267 <dd><samp>v</samp>: second image in list</dd>
268 <dd><samp>s</samp>: current image in list (for %[fx:] otherwise = u)</dd>
269 <dd><samp>t</samp>: index of current image (s) in list</dd>
270 <dd><samp>n</samp>: number of images in list</dd>
271
272 <dd><samp>i</samp>: column offset</dd>
273 <dd><samp>j</samp>: row offset</dd>
274 <dd><samp>p</samp>: pixel to use (absolute or relative to current pixel)</dd>
275
276 <dd><samp>w</samp>: width of this image</dd>
277 <dd><samp>h</samp>: height of this image</dd>
278 <dd><samp>z</samp>: channel depth</dd>
279
280 <dd><samp>r</samp>: red value (from RGBA), of a specific or current pixel</dd>
281 <dd><samp>g</samp>: green</dd>
282 <dd><samp>b</samp>: blue</dd>
283 <dd><samp>a</samp>: alpha</dd>
284 <dd><samp>o</samp>: opacity</dd>
285
286 <dd><samp>c</samp>: cyan value of CMYK color of pixel</dd>
287 <dd><samp>y</samp>: yellow</dd>
288 <dd><samp>m</samp>: magenta</dd>
289 <dd><samp>k</samp>: black</dd>
290
291 <dd><samp>all</samp>: all channels</dd>
292 <dd><samp>this</samp>: this channel</dd>
293
294 <dd><samp>intensity</samp>: pixel intensity</dd>
295
296 <dd><samp>hue</samp>: pixel hue</dd>
297 <dd><samp>saturation</samp>: pixel saturation</dd>
298 <dd><samp>lightness</samp>: pixel lightness</dd>
299 <dd><samp>luma</samp>: pixel luma</dd>
300
301 <dd><samp>page.width</samp>: page width</dd>
302 <dd><samp>page.height</samp>: page height</dd>
303 <dd><samp>page.x</samp>: page x offset</dd>
304 <dd><samp>page.y</samp>: page y offset</dd>
305
306 <dd><samp>printsize.x</samp>: x printsize</dd>
307 <dd><samp>printsize.y</samp>: y printsize</dd>
308
309 <dd><samp>resolution.x</samp>: x resolution</dd>
310 <dd><samp>resolution.y</samp>: y resolution</dd>
311
312 <dd><samp>depth</samp>: image depth</dd>
313 <dd><samp>extent</samp>: image extent</dd>
314 <dd><samp>minima</samp>: image minima</dd>
315 <dd><samp>maxima</samp>: image maxima</dd>
316 <dd><samp>mean</samp>: image mean</dd>
317 <dd><samp>median</samp>: image median</dd>
318 <dd><samp>standard_deviation</samp>: image standard deviation</dd>
319 <dd><samp>kurtosis</samp>: image kurtosis</dd>
320 <dd><samp>skewness</samp>: image skewness (add a channel specifier to compute a statistic for that channel, e.g. depth.r)</dd></dl></dd>
321 <dt class="col-md-4"> iterators:</dt>
322 <dd class="col-md-8"> do(), for(), while()</dd>
323 <dt class="col-md-4"> image attributes:</dt>
324 <dd class="col-md-8"> s.depth, s.kurtosis, s.maxima, s.mean, s.minima, s.resolution.x, s.resolution.y, s.skewness, s.standard_deviation</dd>
325 <dt class="col-md-4"> user settings:</dt>
326 <dd class="col-md-8">define Fx symbols as user settings, e.g. <pre class="p-3 mb-2 text-body-secondary bg-body-tertiary cli"><samp>magick ... -set option:wd1 "%[fx:w/2]" -resize "%[fx:wd1-5]" ...</samp></pre><dd>
327 </dl>
328
329 <h4>The FX Expression</h4>
330
331 <p>An FX expression may include any combination of the following:</p>
332 <dl class="row">
333 <dt class="col-md-4"> <var>x</var> <samp>^</samp> <var>y</var></dt><dd class="col-md-8"> exponentiation (<var>x<sup>y</sup></var>)</dd>
334 <dt class="col-md-4"> <samp>(</samp> ... <samp>)</samp></dt><dd class="col-md-8"> grouping</dd>
335 <dt class="col-md-4"> <var>x</var> <samp>*</samp> <var>y</var></dt><dd class="col-md-8"> multiplication</dd>
336 <dt class="col-md-4"> <var>x</var> <samp>/</samp> <var>y</var></dt><dd class="col-md-8"> division</dd>
337 <dt class="col-md-4"> <var>x</var> <samp>%</samp> <var>y</var></dt><dd class="col-md-8"> modulo</dd>
338 <dt class="col-md-4"> <var>x</var> <samp>+</samp> <var>y</var></dt><dd class="col-md-8"> addition</dd>
339 <dt class="col-md-4"> <var>x</var> <samp>-</samp> <var>y</var></dt><dd class="col-md-8"> subtraction</dd>
340 <dt class="col-md-4"> <var>x</var> <samp>&lt;&lt;</samp> <var>y</var></dt><dd class="col-md-8"> left shift</dd>
341 <dt class="col-md-4"> <var>x</var> <samp>&gt;&gt;</samp> <var>y</var></dt><dd class="col-md-8"> right shift</dd>
342 <dt class="col-md-4"> <var>x</var> <samp>&lt;</samp> <var>y</var></dt><dd class="col-md-8"> boolean relation, return value 1.0 if <var>x</var> &lt; <var>y</var>, otherwise 0.0</dd>
343 <dt class="col-md-4"> <var>x</var> <samp>&lt;=</samp> <var>y</var></dt><dd class="col-md-8"> boolean relation, return value 1.0 if <var>x</var> &lt;= <var>y</var>, otherwise 0.0</dd>
344 <dt class="col-md-4"> <var>x</var> <samp>&gt;</samp> <var>y</var></dt><dd class="col-md-8"> boolean relation, return value 1.0 if <var>x</var> &gt; <var>y</var>, otherwise 0.0</dd>
345 <dt class="col-md-4"> <var>x</var> <samp>&gt;=</samp> <var>y</var></dt><dd class="col-md-8"> boolean relation, return value 1.0 if <var>x</var> &gt;= <var>y</var>, otherwise 0.0</dd>
346 <dt class="col-md-4"> <var>x</var> <samp>==</samp> <var>y</var></dt><dd class="col-md-8"> boolean relation, return value 1.0 if <var>x </var>==<var> y</var>, otherwise 0.0</dd>
347 <dt class="col-md-4"> <var>x</var> <samp>!=</samp> <var>y</var></dt><dd class="col-md-8"> boolean relation, return value 1.0 if <var>x </var>!=<var> y</var>, otherwise 0.0</dd>
348 <dt class="col-md-4"> <var>x</var> <samp>&amp;</samp> <var>y</var></dt><dd class="col-md-8"> binary AND</dd>
349 <dt class="col-md-4"> <var>x</var> <samp>|</samp> <var>y</var></dt><dd class="col-md-8"> binary OR</dd>
350 <dt class="col-md-4"> <var>x</var> <samp>&amp;&amp;</samp> <var>y</var></dt><dd class="col-md-8"> logical AND connective, return value 1.0 if <var>x</var> &gt; 0 and <var>y</var> &gt; 0, otherwise 0.0</dd>
351 <dt class="col-md-4"> <var>x</var> <samp>||</samp> <var>y</var></dt><dd class="col-md-8"> logical OR connective (inclusive), return value 1.0 if <var>x</var> &gt; 0 or <var>y</var> &gt; 0 (or both), otherwise 0.0</dd>
352 <dt class="col-md-4"> <samp>~</samp><var>x</var></dt><dd class="col-md-8"> logical NOT operator, return value 1.0 if <var>not</var> <var>x</var> &gt; 0, otherwise 0.0</dd>
353 <dt class="col-md-4"> <samp>+</samp><var>x</var></dt><dd class="col-md-8"> unary plus, return 1.0*value</dd>
354 <dt class="col-md-4"> <samp>-</samp><var>x</var></dt><dd class="col-md-8"> unary minus, return -1.0*value</dd>
355 <dt class="col-md-4"> <var>condition</var> <samp>?</samp> <var>true-statements</var> <samp>:</samp> <var>false-statements</var> </dt><dd class="col-md-8">ternary conditional expression, return value <var>true-statements</var> if <var>condition</var> != 0, otherwise <var>false-statements</var></dd>
356 <dt class="col-md-4"> <var>x</var> <samp>=</samp> <var>y</var></dt><dd class="col-md-8">assignment; single character variables are reserved, instead use 2 or more characters, letter combinations only (e.g. Xi not X1)</dd>
357 <dt class="col-md-4"> <var>x</var> <samp>;</samp> <var>y</var></dt><dd class="col-md-8">statement separator </dd>
358 <dt class="col-md-4"> <samp>phi</samp></dt><dd class="col-md-8"> constant (1.618034...)</dd>
359 <dt class="col-md-4"> <samp>pi</samp></dt><dd class="col-md-8"> constant (3.14159265359...)</dd>
360 <dt class="col-md-4"> <samp>e</samp></dt><dd class="col-md-8"> constant (2.71828...)</dd>
361 <dt class="col-md-4"> <samp>QuantumRange</samp></dt><dd class="col-md-8"> constant maximum pixel value (255 for Q8, 65535 for Q16)</dd>
362 <dt class="col-md-4"> <samp>QuantumScale</samp></dt><dd class="col-md-8"> constant 1.0/<samp>QuantumRange</samp></dd>
363 <dt class="col-md-4"> <samp>intensity</samp></dt><dd class="col-md-8"> pixel intensity whose value respects the <a href="command-line-options.html#intensity">-intensity</a> option.</dd>
364 <dt class="col-md-4"> <samp>hue</samp></dt><dd class="col-md-8"> pixel hue</dd>
365 <dt class="col-md-4"> <samp>saturation</samp></dt><dd class="col-md-8"> pixel saturation</dd>
366 <dt class="col-md-4"> <samp>lightness</samp></dt><dd class="col-md-8"> pixel lightness; equivalent to 0.5*max(red,green,blue) + 0.5*min(red,green,blue)</dd>
367 <dt class="col-md-4"> <samp>luminance</samp></dt><dd class="col-md-8"> pixel luminance; equivalent to <samp>0.212656*red + 0.715158*green + 0.072186*blue</samp></dd>
368 <dt class="col-md-4"> <samp>red, green, blue</samp>, etc.</dt><dd class="col-md-8"> color names</dd>
369 <dt class="col-md-4"> <samp>#ccc, #cbfed0, #b9e1cc00</samp>, etc.</dt><dd class="col-md-8"> color hex values</dd>
370 <dt class="col-md-4"> <samp>rgb(), rgba(), cmyk(), cmyka(), hsl(), hsla()</samp></dt><dd class="col-md-8"> color functions</dd>
371 <dt class="col-md-4"> <samp>s, t, u, v, n, i, j, w, h, z, r, g, b, a, o, c, y, m, k</samp></dt><dd class="col-md-8"> symbols</dd>
372 <dt class="col-md-4"> <samp>abs(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> absolute value function</dd>
373 <dt class="col-md-4"> <samp>acos(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> arc cosine function</dd>
374 <dt class="col-md-4"> <samp>acosh(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> inverse hyperbolic cosine function</dd>
375 <dt class="col-md-4"> <samp>airy(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> Airy function (max=1, min=0); airy(<var>x</var>)=[jinc(<var>x</var>)]<sup>2</sup>=[2*j1(<var>pi*x</var>)/(<var>pi*x</var>)]<sup>2</sup></dd>
376 <dt class="col-md-4"> <samp>alt(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> sign alternation function (return 1.0 if int(<var>x</var>) is even, -1.0 if int(<var>x</var>) is odd)</dd>
377 <dt class="col-md-4"> <samp>asin(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> arc sine function</dd>
378 <dt class="col-md-4"> <samp>asinh(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> inverse hyperbolic sine function</dd>
379 <dt class="col-md-4"> <samp>atan(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> arc tangent function</dd>
380 <dt class="col-md-4"> <samp>atanh(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> inverse hyperbolic tangent function</dd>
381 <dt class="col-md-4"> <samp>atan2(</samp><var>y</var>,<var>x</var><samp>)</samp></dt><dd class="col-md-8"> arc tangent function of two variables</dd>
382 <dt class="col-md-4"> <samp>ceil(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8">smallest integral value not less than argument</dd>
383 <dt class="col-md-4"> <samp>channel(</samp>...<samp>)</samp></dt><dd class="col-md-8">supports from zero to five arguments, e.g., channel(0.1) sets the first channel to 0.1 and zero's the other channels.</dd>
384 <dt class="col-md-4"> <samp>clamp(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> clamp value</dd>
385 <dt class="col-md-4"> <samp>cos(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> cosine function</dd>
386 <dt class="col-md-4"> <samp>cosh(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> hyperbolic cosine function</dd>
387 <dt class="col-md-4"> <samp>debug(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> print <var>x</var> (useful for debugging your expression)</dd>
388 <dt class="col-md-4"> <samp>do(</samp><var>statements</var>, <var>condition</var><samp>)</samp></dt><dd class="col-md-8"> iterate while the condition is not equal to 0</dd>
389 <dt class="col-md-4"> <samp>drc(</samp><var>x</var>,<var>y</var><samp>)</samp></dt><dd class="col-md-8"> dynamic range compression (knee curve); drc(<var>x</var>,<var>y</var>)=(<var>x</var>)/(<var>y</var>*(<var>x</var>-1)+1); -1&lt;<var>y</var>&lt;1 </dd>
390 <dt class="col-md-4"> <samp>erf(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> error function</dd>
391 <dt class="col-md-4"> <samp>exp(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> natural exponential function (<var>e<sup>x</sup></var>)</dd>
392 <dt class="col-md-4"> <samp>floor(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> largest integral value not greater than argument</dd>
393 <dt class="col-md-4"> <samp>for(</samp><var>initialize</var>, <var>condition</var>, <var>statements</var><samp>)</samp></dt><dd class="col-md-8"> iterate while the condition is not equal to 0</dd>
394 <dt class="col-md-4"> <samp>gauss(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> gaussian function; gauss(<var>x</var>)=exp(<var>-x*x/2</var>)/sqrt(2*pi)</dd>
395 <dt class="col-md-4"> <samp>gcd(</samp><var>x</var>,<var>y</var><samp>)</samp></dt><dd class="col-md-8"> greatest common denominator</dd>
396 <dt class="col-md-4"> <samp>hypot(</samp><var>x</var>,<var>y</var><samp>)</samp></dt><dd class="col-md-8"> the square root of x<sup>2</sup>+y<sup>2</sup></dd>
397 <dt class="col-md-4"> <samp>if(</samp><var>condition</var>, <var>nonzero-statements</var>, <var>zero-statements</var><samp>)</samp></dt><dd class="col-md-8"> interpret expression depending on condition</dd>
398 <dt class="col-md-4"> <samp>int(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> greatest integer function (return greatest integer less than or equal to <var>x</var>)</dd>
399 <dt class="col-md-4"> <samp>isnan(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8">return 1.0 if <var>x</var> is NAN, 0.0 otherwise</dd>
400 <dt class="col-md-4"> <samp>j0(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> Bessel functions of <var>x</var> of the first kind of order 0</dd>
401 <dt class="col-md-4"> <samp>j1(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> Bessel functions of <var>x</var> of the first kind of order 1</dd>
402 <dt class="col-md-4"> <samp>jinc(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> jinc function (max=1, min=-0.1323); jinc(<var>x</var>)=2*j1(pi*<var>x</var>)/(pi*<var>*x</var>)</dd>
403 <dt class="col-md-4"> <samp>ln(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> natural logarithm function</dd>
404 <dt class="col-md-4"> <samp>log(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> logarithm base 10</dd>
405 <dt class="col-md-4"> <samp>logtwo(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> logarithm base 2</dd>
406 <dt class="col-md-4"> <samp>ln(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> natural logarithm</dd>
407 <dt class="col-md-4"> <samp>max(</samp><var>x</var>, <var>y</var><samp>)</samp></dt><dd class="col-md-8"> maximum of <var>x</var> and <var>y</var></dd>
408 <dt class="col-md-4"> <samp>min(</samp><var>x</var>, <var>y</var><samp>)</samp></dt><dd class="col-md-8"> minimum of <var>x</var> and <var>y</var></dd>
409 <dt class="col-md-4"> <samp>mod(</samp><var>x</var>, <var>y</var><samp>)</samp></dt><dd class="col-md-8"> floating-point remainder function</dd>
410 <dt class="col-md-4"> <samp>not(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> return 1.0 if <var>x</var> is zero, 0.0 otherwise</dd>
411 <dt class="col-md-4"> <samp>pow(</samp><var>x</var>,<var>y</var><samp>)</samp></dt><dd class="col-md-8"> power function (<var>x<sup>y</sup></var>)</dd>
412 <dt class="col-md-4"> <samp>rand()</samp></dt><dd class="col-md-8"> value uniformly distributed over the interval [0.0, 1.0) with a 2 to the 128th-1 period</dd>
413 <dt class="col-md-4"> <samp>round()</samp></dt><dd class="col-md-8"> round to integral value, regardless of rounding direction</dd>
414 <dt class="col-md-4"> <samp>sign(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> return -1.0 if <var>x</var> is less than 0.0 otherwise 1.0</dd>
415 <dt class="col-md-4"> <samp>sin(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> sine function</dd>
416 <dt class="col-md-4"> <samp>sinc(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> sinc function (max=1, min=-0.21); sinc(<var>x</var>)=sin(<var>pi*x</var>)/(<var>pi*x</var>)</dd>
417 <dt class="col-md-4"> <samp>squish(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> squish function; squish(<var>x</var>)=1.0/(1.0+exp(<var>-x</var>))</dd>
418 <dt class="col-md-4"> <samp>sinh(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> hyperbolic sine function</dd>
419 <dt class="col-md-4"> <samp>sqrt(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> square root function</dd>
420 <dt class="col-md-4"> <samp>tan(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> tangent function</dd>
421 <dt class="col-md-4"> <samp>tanh(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> hyperbolic tangent function</dd>
422 <dt class="col-md-4"> <samp>trunc(</samp><var>x</var><samp>)</samp></dt><dd class="col-md-8"> round to integer, towards zero</dd>
423 <dt class="col-md-4"> <samp>while(</samp><var>condition</var>, <var>statements</var><samp>)</samp></dt><dd class="col-md-8"> iterate while the condition is not equal to 0</dd>
424 <dt class="col-md-4"> <samp>image.depth, image.kurtosis, image.maxima, image.mean, image.median, image.minima, image.resolution.x, image.resolution.y, image.skewness, image.standard_deviation</samp></dt><dd class="col-md-8"> image attributes</dd>
425 </dl>
426 <p>The expression semantics include these rules:</p>
427
428 <ul>
429 <li>symbols are case insensitive</li>
430 <li>only one ternary conditional (e.g. x ? y : z) per statement</li>
431 <li>statements are assignments or the final expression to return</li>
432 <li>an assignment starts a statement, it is not an operator</li>
433 <li>single character variables are reserved. Assignments to reserved built-ins throw an exception; e.g. <samp>r=3.0; r</samp> returns <em>Attempted assignment to non-UserSymbol 'r' at '3.0'</em>.</li>
434 <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>
435 <li>care must be exercised when using the slash ('/') symbol. The string of characters <var>1/2x</var> 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>
436 <li>As <samp>--<samp> is the variable decrement operator, use parenthesis to subtract a negative number, e.g, <samp>-4-(-5)</samp>.</li>
437 </ul>
438 <br/>
439
440
441 <h4>Source Images</h4>
442
443 <p>The symbols <samp>u</samp> and <samp>v</samp> 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 <samp>u</samp>), with a zero index for the beginning of the sequence. A negative index counts from the end. For example, <samp>u[0]</samp> is the first image in the sequence, <samp>u[2]</samp> is the third, <samp>u[-1]</samp> is the last image, and <samp>u[t]</samp> is the current image. The current image can also be referenced by <samp>s</samp>. If the sequence number exceeds the length of the sequence, the count is wrapped. Thus in a 3-image sequence, <samp>u[-1]</samp>, <samp>u[2]</samp>, and <samp>u[5]</samp> all refer to the same (third) image.</p>
444
445 <p>As an example, we form an image by averaging the first image and third images (the second (index 1) image is ignored and just junked):</p>
446
447 <pre class="p-3 mb-2 text-body-secondary bg-body-tertiary cli"><samp>magick image1.jpg image2.jpg image3.jpg -fx "(u+u[2])/2" image.jpg
448 </samp></pre>
449
450 <p>By default, the image to which <samp>p</samp>, <samp>r</samp>, <samp>g</samp>, <samp>b</samp>, <samp>a</samp>, etc., are applied is the current image <samp>s</samp> in the image list. This is equivalent to <samp>u</samp> except when used in an escape sequence <samp>%[fx:...]</samp>. </p>
451
452 <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="command-line-options.html#channel">-channel red</a> instructs <a href="command-line-options.html#fx">-fx</a> to modify only the green channel; nothing in the red or blue channels will change. It is instructive to ponder why the result is not symmetric.</p>
453
454 <pre class="p-3 mb-2 text-body-secondary bg-body-tertiary cli"><samp>magick logo: -flop logo: -resize "20%" -channel green -fx "(u+v)/2" image.jpg
455 </samp></pre>
456
457 <ul>
458 <a href="../images/logo-sm-flop.png"><img src="../images/logo-sm-flop.png" width="128" height="96" alt="logo-sm-flop.png" /></a>
459 <a href="../images/logo-sm.png"><img src="../images/logo-sm.png" width="128" height="96" alt="logo-sm.png" /></a>
460 <img style="margin-top:38px; margin-bottom:38px;" src="../images/right.gif" width="20" height="20" alt="==>" />
461 <a href="../images/logo-sm-fx.png"><img src="../images/logo-sm-fx.png" width="128" height="96" alt="logo-sm-fx.png" /></a>
462 </ul>
463
464 <br/>
465 <h4>Accessing Pixels</h4>
466
467 <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>
468
469 <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 <samp>p</samp>. For example,</p>
470
471 <pre class="p-3 mb-2 text-body-secondary bg-body-tertiary"><samp>p[-1].g green value of pixel to the immediate left of the current pixel
472 p[-1,-1].r red value of the pixel diagonally left and up from current pixel
473 </samp></pre>
474
475 <p>To specify an absolute position, use braces, rather than brackets.</p>
476
477 <pre class="p-3 mb-2 text-body-secondary bg-body-tertiary"><samp>p{0,0}.r red value of the pixel in the upper left corner of the image
478 p{12,34}.b blue pixel value at column number 12, row 34 of the image
479 </samp></pre>
480
481 <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="command-line-options.html#interpolate">-interpolate</a> setting.</p>
482
483 <p>A position outside the boundary of the image retrieves a value dictated by the <a href="command-line-options.html#virtual-pixel">-virtual-pixel</a> option setting.</p>
484
485 <p>Specify <samp>u.r</samp> to specify the red channel of the current image. If you don't specify a channel qualifier, you get the current channel. Use <samp>mean.this</samp> to set the output channel to the mean of just the input channel. Use <samp>mean.all</samp> to set the overall mean of the input channels.</p>
486
487 <h4>Apply an Expression to Select Image Channels</h4>
488
489 <p>Use the <a href="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 <samp>alpha.png</samp> with the average of the green channels from the images <samp>alpha.png</samp> and <samp>beta.png</samp>, use:</p>
490
491 <pre class="p-3 mb-2 text-body-secondary bg-body-tertiary cli"><samp>magick alpha.png beta.png -channel red -fx "(u.g+v.g)/2" gamma.png
492 </samp></pre>
493
494
495 <h4>Results</h4>
496
497 <p>The <a href="command-line-options.html#fx">-fx</a> operator evaluates the given expression for each channel (set by <a href="command-line-options.html#channel">-channel</a>) of each pixel in the first image (<samp>u</samp>) 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 <samp>alpha.png</samp> replaces both of the original images, <samp>alpha.png</samp> and <samp>beta.png</samp>, before being saved as <samp>gamma.png</samp>.</p>
498
499 <p>The current image <samp>s</samp> is set to the first image in the sequence (<samp>u</samp>), and <samp>t</samp> to its index, 0. The symbols <samp>i</samp> and <samp>j</samp> reference the current pixel being processed.</p>
500
501
502 <p>For use with <a href="command-line-options.html#format_identify_">-format</a>, the value-escape <samp>%[fx:]</samp> is evaluated just once for each image in the current image sequence. As each image in the sequence is being evaluated, <samp>s</samp> and <samp>t</samp> successively refer to the current image and its index, while <samp>i</samp> and <samp>j</samp> are set to zero, and the current channel set to red (<a href="command-line-options.html#channel">-channel</a> is ignored). An example:</p>
503
504 <pre class="p-3 mb-2 text-body-secondary bg-body-tertiary"><samp>$ magick canvas:'rgb(25%,50%,75%)' rose: -colorspace gray \
505 -format 'Red channel of NW corner of image #%[fx:t] is %[fx:s]\n' info:
506 Red channel of NW corner of image #0 is 0.464883
507 Red channel of NW corner of image #1 is 0.184582
508 </samp></pre>
509
510 <p>Here we use the image indexes to <var>rotate</var> each image differently, and use <samp>-set</samp> with the image index to set a different <var>pause delay</var> on the first image in the animation:</p>
511
512 <pre class="p-3 mb-2 text-body-secondary bg-body-tertiary cli"><samp>magick rose: -duplicate 29 -virtual-pixel Gray -distort SRT '%[fx:360.0*t/n]' \
513 -set delay '%[fx:t == 0 ? 240 : 10]' -loop 0 rose.gif
514 </samp></pre>
515
516 <p>This example tests the difference between two images, measured by RMSE. If the difference is greater than 0.1 it returns 1; otherwise it returns 0:</p>
517
518 <pre class="p-3 mb-2 text-body-secondary bg-body-tertiary cli"><samp>magick water.png reference.png -metric RMSE -compare -format "%[fx:%[distortion]>0.1]" info:</samp></pre>
519
520 <p>The color-escape <samp>%[pixel:]</samp> or <samp>%[hex:]</samp> is evaluated once per image and per color channel in that image (<a href="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 <samp>i</samp> and <samp>j</samp> are set to zero, and <samp>s</samp> and <samp>t</samp> refer to each successively current image and index.</p>
521
522 </div>
523 </main><!-- /.container -->
524 <footer class="text-center pt-5 my-5 text-body-secondary border-top">
525 <div class="container-fluid">
526 <a href="security-policy.html">Security</a> •
527 <a href="news.html">News</a>
528
529 <a href="#"><img class="d-inline" id="wand" alt="And Now a Touch of Magick" width="16" height="16" src="../images/wand.ico"/></a>
530
531 <a href="links.html">Related</a> •
532 <a href="sitemap.html">Sitemap</a>
533 <br/>
534 <a href="support.html">Sponsor</a> •
535 <a href="cite.html">Cite</a> •
536 <a href="http://pgp.mit.edu/pks/lookup?op=get&amp;search=0x89AB63D48277377A">Public Key</a> •
537 <a href="../www/../www/../www/../www/https://imagemagick.org/script/contact.php">Contact Us</a>
538 <br/>
539 <a href="https://github.com/imagemagick/imagemagick" rel="noopener" target="_blank" aria-label="GitHub"><svg xmlns="http://www.w3.org/2000/svg" class="navbar-nav-svg" viewBox="0 0 512 499.36" width="2%" height="2%" role="img" focusable="false"><title>GitHub</title><path fill="currentColor" fill-rule="evenodd" d="M256 0C114.64 0 0 114.61 0 256c0 113.09 73.34 209 175.08 242.9 12.8 2.35 17.47-5.56 17.47-12.34 0-6.08-.22-22.18-.35-43.54-71.2 15.49-86.2-34.34-86.2-34.34-11.64-29.57-28.42-37.45-28.42-37.45-23.27-15.84 1.73-15.55 1.73-15.55 25.69 1.81 39.21 26.38 39.21 26.38 22.84 39.12 59.92 27.82 74.5 21.27 2.33-16.54 8.94-27.82 16.25-34.22-56.84-6.43-116.6-28.43-116.6-126.49 0-27.95 10-50.8 26.35-68.69-2.63-6.48-11.42-32.5 2.51-67.75 0 0 21.49-6.88 70.4 26.24a242.65 242.65 0 0 1 128.18 0c48.87-33.13 70.33-26.24 70.33-26.24 14 35.25 5.18 61.27 2.55 67.75 16.41 17.9 26.31 40.75 26.31 68.69 0 98.35-59.85 120-116.88 126.32 9.19 7.9 17.38 23.53 17.38 47.41 0 34.22-.31 61.83-.31 70.23 0 6.85 4.61 14.81 17.6 12.31C438.72 464.97 512 369.08 512 256.02 512 114.62 397.37 0 256 0z"/></svg></a> •
540 <a href="https://twitter.com/imagemagick" rel="noopener" target="_blank" aria-label="Twitter"><svg xmlns="http://www.w3.org/2000/svg" class="navbar-nav-svg" viewBox="0 0 300 300" width="2%" height="2%" role="img" focusable="false"><title>Twitter</title><path d="M178.57 127.15 290.27 0h-26.46l-97.03 110.38L89.34 0H0l117.13 166.93L0 300.25h26.46l102.4-116.59 81.8 116.59h89.34M36.01 19.54H76.66l187.13 262.13h-40.66"/></svg></a>
541 <br/>
542 <small>Copyright © 1999 ImageMagick Studio LLC</small>
543 </div>
544 </footer>
545 </div>
546
547 <!-- Javascript assets -->
548 <script src="assets/bootstrap.bundle.min.js" ></script>
549 </body>
550 </html>
551 <!-- Magick Cache 1st March 2025 19:23 -->