fx.html revision 5292344af862c8d10e50c4e9300a591aad3acae5
1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr"> 5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<head> 6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <meta name="verify-v1" content="g222frIIxcQTrvDR3NBRUSKP3AnMNoqxOkIniCEkV7U="/> 8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <title>ImageMagick: The Fx Special Effects Image Operator</title> 9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <meta http-equiv="Content-Language" content="en-US"/> 10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <meta http-equiv="Reply-to" content="magick-users@imagemagick.org"/> 12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <meta name="Application-name" content="ImageMagick"/> 13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <meta name="Description" content="ImageMagick is a software suite to create, edit, compose, or convert bitmap images in a variety of formats. Use ImageMagick to scale, rotate, shear, distort and transform images."/> 14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <meta name="Application-url" content="http://www.imagemagick.org"/> 15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <meta name="Generator" content="PHP"/> 16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <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"/> 17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <meta name="Rating" content="GENERAL"/> 18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <meta name="Robots" content="INDEX, FOLLOW"/> 19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <meta name="Generator" content="ImageMagick Studio LLC"/> 20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <meta name="Author" content="ImageMagick Studio LLC"/> 21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <meta name="Revisit-after" content="2 DAYS"/> 22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <meta name="Resource-type" content="document"/> 23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <meta name="Copyright" content="Copyright (c) 1999-2011 ImageMagick Studio LLC"/> 24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <meta name="Distribution" content="Global"/> 25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <link rel="icon" href="/images/wand.png"/> 26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <link rel="shortcut icon" href="/images/wand.ico" type="images/x-icon"/> 2719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <link rel="meta" type="application/rdf+xml" title="ICI" href="http://imagemagick.org/ici.rdf"/> 28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css" type="text/css" /> 29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <style type="text/css" media="all"> 30894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman @import url("/www/magick.css"); 31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman </style> 32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> 33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <script type="text/javascript" src="/fancybox/jquery.fancybox-1.3.4.pack.js"></script> 34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <link rel="stylesheet" type="text/css" href="/fancybox/jquery.fancybox-1.3.4.css" media="screen" /> 35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <script type="text/javascript"> 36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman $(document).ready(function() { 3719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman $("a[href$=.jpg],a[href$=.png],a[href$=.gif]").fancybox({ 3819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 'transitionIn' : 'elastic', 3919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 'transitionOut' : 'elastic', 4019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 'overlayShow' : false, 41894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 'opacity' : true 42894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman }); 43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman }); 4419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman </script> 45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman</head> 4619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<body id="www-imagemagick-org"> 48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<div class="titlebar"> 49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<a href="/index.html"> 50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <img src="/images/script.png" alt="[ImageMagick]" 5119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman style="width: 350px; height: 60px; margin: 28px auto; float: left;" /></a> 52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<a href="http://www.networkredux.com"> 53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <img src="/images/networkredux.png" alt="[sponsor]" 5419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman style="margin-top: 42px; border: 0px; float: left;" /></a> 5519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<a href="http://www.imagemagick.org/discourse-server/"> 5619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <img src="/images/logo.jpg" alt="" 5719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman style="width: 114px; height: 118px; border: 0px; float: right;" /></a> 5819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<a href="/index.html"> 5919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <img src="/images/sprite.jpg" alt="" 6019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman style="width: 114px; height: 118px; border: 0px; float: right;" /></a> 6119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 6219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 6319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="westbar"> 6419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 6519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="menu"> 6619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="About ImageMagick" href="/index.html">About ImageMagick</a> 6719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 6819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sep"></div> 6919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="menu"> 7019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Binary Releases" href="/www/binary-releases.html">Binary Releases</a> 7119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 7219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sub"> 7319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Binary Release: Unix" href="/www/binary-releases.html#unix">Unix</a> 7419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 7519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sub"> 7619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Binary Release: MacOS X" href="/www/binary-releases.html#macosx">Mac OS X</a> 7719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 7819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sub"> 7919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Binary Release: Windows" href="/www/binary-releases.html#windows">Windows</a> 8019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 8119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sep"></div> 8219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="menu"> 8319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Command-line Tools" href="/www/command-line-tools.html">Command-line Tools</a> 8419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 8519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sub"> 8619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Command-line Tools: Processing" href="/www/command-line-processing.html">Processing</a> 8719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 8819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sub"> 8919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Command-line Tools: Options" href="/www/command-line-options.html">Options</a> 9019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 9119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sub"> 9219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Command-line Tools: Usage" href="http://www.imagemagick.org/Usage/">Usage</a> 9319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 9419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="menu"> 9519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Program Interfaces" href="/www/api.html">Program Interfaces</a> 9619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 9719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sub"> 9819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Program Interface: MagickWand" href="/www/magick-wand.html">MagickWand</a> 9919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 10019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sub"> 10119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Program Interface: MagickCore" href="/www/magick-core.html">MagickCore</a> 10219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 10319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sub"> 10419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Program Interface: PerlMagick" href="/www/perl-magick.html">PerlMagick</a> 10519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 10619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sub"> 10719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Program Interface: Magick++" href="/www/magick++.html">Magick++</a> 10819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 10919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sep"></div> 11019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="menu"> 11119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Install from Source" href="/www/install-source.html">Install from Source</a> 11219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 11319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sub"> 11419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Install from Source: Unix" href="/www/install-source.html#unix">Unix</a> 11519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 11619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sub"> 11719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Install from Source: Windows" href="/www/install-source.html#windows">Windows</a> 11819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman </div> 11919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="menu"> 12019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Resources" href="/www/resources.html">Resources</a> 12119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 12219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="menu"> 12319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Architecture" href="/www/architecture.html">Architecture</a> 12419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 12519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="menu"> 12619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Download" href="/www/download.html">Download</a> 12719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 12819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sep"></div> 12919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="menu"> 13019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Search" href="/www/search.html">Search</a> 13119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 13219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sep"></div> 13319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="menu"> 13419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Site Map" href="/www/sitemap.html">Site Map</a> 13519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 136894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<div class="sub"> 137894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <a title="Site Map: Links" href="/www/links.html">Links</a> 138894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman</div> 139894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<div class="sep"></div> 140894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<div class="menu"> 141894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <a title="Sponsors" href="/www/sponsors.html">Sponsors:</a> 14219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 143894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<div class="sponsbox"> 144894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<div class="sponsor"> 145894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <a title="Sponsor: Web Hosting" href="http://www.bodhost.com/hosting.shtml">Web Hosting</a><!-- 201104010090 --> 146894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman</div> 14719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sponsor"> 148894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <a title="Sponsor: Druckerei" href="http://print24.com/de/">Druckerei</a><!-- 201110010720 --> 149894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman</div> 150894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<div class="sponsor"> 15119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Sponsor: Image Converter" href="http://www.batchphoto.com">Image Converter</a><!-- 201103010900 Bits Coffee--> 15219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 15319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sponsor"> 15419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Sponsor: Flyer drucken" href="http://www.online-druck.biz">Flyer drucken</a><!-- 201109010900 Floeter--> 15519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 15619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="sponsor"> 15719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a title="Sponsor: Fernsehdienst Berlin" href="http://www.atlas-multimedia.de">Fernsehdienst Berlin</a><!-- 2011050100025 atlas.multimedia--> 15819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 15919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 16019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 16119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 16219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 16319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="eastbar"> 16419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <script type="text/javascript"> 16519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <!-- 16619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman google_ad_client = "pub-3129977114552745"; 16719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman google_ad_slot = "0574824969"; 16819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman google_ad_width = 160; 169894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman google_ad_height = 600; 170894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman //--> 17119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman </script> 17219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <script type="text/javascript" 17319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 17419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman </script> 17519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 17619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 177894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<div class="main"> 178894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 179894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<h1>Apply Special Effects to an Image with an Fx Expression</h1> 180894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<p class="navigation-index">[<a href="#fx">The Fx Special Effects Image Operator</a> • <a href="#anatomy">The Anatomy of an Fx Expression</a>]</p> 18119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 18219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<a id="fx"></a> 18319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="doc-section"> 18419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 18519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<p>Use the Fx special effects image operator to apply a mathematical expression to an image or image channels. Use Fx to:</p> 18619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 18719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<ul> 188894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <li>create canvases, gradients, mathematical colormaps</li> 189894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <li>move color values between images and channels</li> 190894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <li>translate, flip, mirror, rotate, scale, shear and generally distort images</li> 19119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <li>merge or composite multiple images together</li> 19219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <li>convolve or merge neighboring pixels together</li> 19319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <li>generate image metrics or 'fingerprints'</li> 19419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</ul> 19519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 19619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<p>The expression can be simple:</p> 19719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 19819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<p class='crt'><span class="crtprompt"> $magick> </span><span class='crtin'>convert -size 64x64 xc:black -channel blue -fx "1/2" fx_navy.png</span></p> 19919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<p>Here, we convert a black to a navy blue image:</p> 20019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 20119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<p class="image"> 202894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <a href="/images/black.png"><img src="/images/black.png" width="64" height="64" alt="black" /></a> 20319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <img style="margin-top:22px; margin-bottom:22px;" src="/images/right.gif" width="20" height="20" alt="==>" /> 204894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <a href="/images/navy.png"><img src="/images/navy.png" width="64" height="64" alt="navy" /></a> 20519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</p> 20619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 207894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<p>Or the expression can be complex:</p> 20819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 20919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<p class='crt'><span class="crtprompt"> $magick> </span><span class='crtin'>convert rose.jpg \ <br/> 21019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman -fx "(1.0/(1.0+exp(10.0*(0.5-u)))-0.006693)*1.0092503" \ <br/> 211894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman rose-sigmoidal.png</span></p> 21219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<p>This expression results in a high contrast version of the image:</p> 21319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 21419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<p class="image"> 21519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a href="/images/rose.jpg"><img src="/images/rose.jpg" width="70" height="46" alt="rose" /></a> 216894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <img style="margin-top:13px; margin-bottom:13px;" src="/images/right.gif" width="20" height="20" alt="==>" /> 21719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a href="/images/rose-sigmoidal.png"><img src="/images/rose-sigmoidal.png" width="70" height="46" alt="rose-sigmoidal" /></a> 21819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</p> 21919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 22019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<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> 22119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 22219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<p class='crt'><span class="crtprompt"> $magick> </span><span class='crtin'>convert -size 70x70 xc: \ <br/> 22319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman -fx "Xi=i-w/2; Yj=j-h/2; 1.2*(0.5-hypot(Xi,Yj)/70.0)+0.5" \ <br/> 22419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman radial-gradient.png</span></p> 22519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<p>The command above returns this image:</p> 226894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 227894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<p class="image"> 22819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <a href="/images/radial-gradient.png"><img src="/images/radial-gradient.png" width="70" height="70" alt="radial-gradient" /></a> 229894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman</p> 230894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<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> 23119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 232894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<p>The next section discusses the Fx expression language.</p> 233894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 234894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman</div> 235894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 236894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<h2><a id="anatomy"></a>The Anatomy of an Fx Expression</h2> 237894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<div class="doc-section"> 238894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 239894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<h3>The Fx Expression Language</h3> 240894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<div class="doc-section"> 241894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 242894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<p>The formal Fx expression language is defined here:</p> 24319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 244894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<dl class="doc"> 24519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <dt class="doc"> numbers:</dt> 246894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <dd> integer, floating point, or scientfic notation (+/- required, e.g. 3.81469e-06)</dd> 247894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <dt class="doc"> constants: </dt> 24819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <dd> e, Epsilon, QuantumRange, QuantumScale, Opaque, Pi, Transparent</dd> 24919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman <dt class="doc"> Fx operators (in order of precedence): </dt> 250894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <dd> ^ (power), unary -, *, /, % (modulo), +, -, 251894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <<, >>, <, <=, >, >=, ==, !=, 252894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman & (bitwise AND), | (bitwise OR), 253894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman && (logical AND), || (logical OR), 25419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman ~ (logical NOT), ?: (ternary conditional)</dd> 255894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <dt class="doc"> math functions: </dt> 256894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <dd> abs(), acos(), airy(), alt(), asin(), atan(), atan2(), ceil(), cos(), cosh(), debug(), exp(), floor(), 257894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman hypot(), int(), j0(), j1(), jinc(), ln(), log(), logtwo(), max(), min(), mod(), pow(), rand(), round(), 258894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman sign(), sin(), sinc(), sinh(), sqrt(), tan(), tanh(), trunc()</dd> 259894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <dt class="doc"> channel functions: </dt> 260894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <dd> channel(r,g,b,a), channel(c,m,y,k,a)</dd> 261894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <dt class="doc"> color names:</dt> 262894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <dd> red, cyan, black, etc.</dd> 263894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <dt class="doc"> color functions:</dt> 264894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <dd> rgb(), rgba(), cmyk(), cmyka(), hsl(), hsla()</dd> 265894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <dt class="doc"> color hex values:</dt> 266894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <dd> #ccc, #cbfed0, #b9e1cc00</dd> 267894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <dt class="doc"> symbols:</dt> 268894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman <dd style="white-space:pre"> 26919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman s = current image in sequence 27019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman t = scene number of current image in sequence 27119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman u = first image in sequence 272894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman v = second image in sequence 27319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman n = number of images in sequence 27419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 27519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman i = column offset 276894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman j = row offset 277894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman p = pixel to use (absolute or relative to current pixel) 27819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 27919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman w = width of this image 28019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman h = height of this image 28119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman z = channel depth 28219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 28319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman r = red value (from RGBA), of a specific or current pixel 28419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman g = green '' 28519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman b = blue '' 28619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman a = alpha '' 28719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman o = opacity '' 28819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 28919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman c = cyan value of CMYK color of pixel 29019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman y = yellow '' 29119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman m = magenta '' 29219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman k = black '' 29319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 29419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman intensity = pixel intensity 29519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 29619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman hue = pixel hue 29719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman saturation = pixel saturation 29819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman lightness = pixel lightness 29919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman luminance = pixel luminance 30019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 30119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman page.width = page width 30219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman page.height = page height 30319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman page.x = page x offset 30419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman page.y = page y offset 30519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 306894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman resolution.x = x resolution 30719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman resolution.y = y resolution 308894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 30919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman depth = image depth 310894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman minima = image minima 31119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman maxima = image maxima 31219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman mean = image mean 31319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman standard_deviation = image standard deviation 31419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman kurtosis = image kurtosis 31519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman skewness = image skewness 31619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman (add a channel specifier to compute a statistic for that channel, e.g. depth.r) 31719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman </dd> 31819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</dl> 31919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 32019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman</div> 32119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 32219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<h3>The Fx Expression</h3> 32319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<div class="doc-section"> 32419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 32519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<p>An Fx expression may include any combination of the following:</p> 32619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<ul> 32719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<li> <em>x</em> <kbd>^</kbd> <em>y</em>: exponentiation (<em>x<sup>y</sup></em>)</li> 328894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<li> <kbd>(</kbd> ... <kbd>)</kbd>: grouping</li> 329894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<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> 33019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<li> <em>x</em> <kbd>/</kbd> <em>y</em>: division</li> 33119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<li> <em>x</em> <kbd>%</kbd> <em>y</em>: modulo</li> 332894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<li> <em>x</em> <kbd>+</kbd> <em>y</em>: addition</li> 333894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<li> <em>x</em> <kbd>-</kbd> <em>y</em>: subtraction</li> 334894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<li> <em>x</em> <kbd><<</kbd> <em>y</em>: left shift</li> 335894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<li> <em>x</em> <kbd>>></kbd> <em>y</em>: right shift</li> 33619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<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> 33719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<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> 33819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman<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> 339894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<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> 340894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<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> 341894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<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> 342894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<li> <em>x</em> <kbd>&</kbd> <em>y</em>: binary AND</li> 343894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<li> <em>x</em> <kbd>|</kbd> <em>y</em>: binary OR</li> 344894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<li> <em>x</em> <kbd>&&</kbd> <em>y</em>: logical AND connective, return value 1.0 if <em>x</em> > 0 and <em>y</em> > 0, otherwise 0.0</li> 345894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<li> <em>x</em> <kbd>||</kbd> <em>y</em>: logical OR connective (inclusive), return value 1.0 if <em>x</em> > 0 or <em>y</em> > 0 (or both), otherwise 0.0</li> 346894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<li> <kbd>~</kbd><em>x</em>: logical NOT operator, return value 1.0 if <em>not</em> <em>x</em> > 0, otherwise 0.0</li> 347894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<li> <kbd>+</kbd><em>x</em>: unary plus, return 1.0*value</li> 348894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<li> <kbd>-</kbd><em>x</em>: unary minus, return -1.0*value</li> 349894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<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> 350894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<li> <em>x</em> <kbd>=</kbd> <em>y</em>: assignment; assignment variables are restricted to letter combinations only (e.g. Xi not X1)</li> 351894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman<li> <em>x</em> <kbd>;</kbd> <em>y</em>: statement separator </li> 352<li> <kbd>pi</kbd>: constant (3.141659...)</li> 353<li> <kbd>e</kbd>: constant (2.71828...)</li> 354<li> <kbd>QuantumRange</kbd>: constant maximum pixel value (255 for Q8, 65535 for Q16)</li> 355<li> <kbd>QuantumScale</kbd>: constant 1.0/<kbd>QuantumRange</kbd></li> 356<li> <kbd>intensity</kbd>: pixel intensity; equivalent to 0.299*red+0.587*green+0.114*blue</li> 357<li> <kbd>hue</kbd>: pixel hue</li> 358<li> <kbd>saturation</kbd>: pixel saturation</li> 359<li> <kbd>lightness</kbd>: pixel lightness; equivalent to 0.5*max(red,green,blue) + 0.5*min(red,green,blue)</li> 360<li> <kbd>luminance</kbd>: pixel luminance; equivalent to 0.2126*red + 0.7152*green + 0.0722*blue</li> 361<li> <kbd>red, green, blue</kbd>, etc.: color names</li> 362<li> <kbd>#ccc, #cbfed0, #b9e1cc00</kbd>, etc.: color hex values</li> 363<li> <kbd>rgb(), rgba(), cmyk(), cmyka(), hsl(), hsla()</kbd>: color functions</li> 364<li> <kbd>s, t, u, v, n, i, j, w, h, z, r, g, b, a, o, c, y, m, k</kbd>: symbols</li> 365<li> <kbd>abs(</kbd><em>x</em><kbd>)</kbd>: absolute value function</li> 366<li> <kbd>acos(</kbd><em>x</em><kbd>)</kbd>: arc cosine function</li> 367<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> 368<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> 369<li> <kbd>asin(</kbd><em>x</em><kbd>)</kbd>: arc sine function</li> 370<li> <kbd>atan(</kbd><em>x</em><kbd>)</kbd>: arc tangent function</li> 371<li> <kbd>atan2(</kbd><em>y</em>,<em>x</em><kbd>)</kbd>: arc tangent function of two variables</li> 372<li> <kbd>ceil(</kbd><em>x</em><kbd>)</kbd>: smallest integral value not less than argument</li> 373<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> 374<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> 375<li> <kbd>cos(</kbd><em>x</em><kbd>)</kbd>: cosine function</li> 376<li> <kbd>cosh(</kbd><em>x</em><kbd>)</kbd>: hyperbolic cosine function</li> 377<li> <kbd>debug(</kbd><em>x</em><kbd>)</kbd>: print <em>x</em> (useful for debugging your expression)</li> 378<li> <kbd>exp(</kbd><em>x</em><kbd>)</kbd>: natural exponential function (<em>e<sup>x</sup></em>)</li> 379<li> <kbd>floor(</kbd><em>x</em><kbd>)</kbd>: largest integral value not greater than argument</li> 380<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> 381<li> <kbd>int(</kbd><em>x</em><kbd>)</kbd>: greatest integer function (return greatest integer less than or equal to <em>x</em>)</li> 382<li> <kbd>j0(</kbd><em>x</em><kbd>)</kbd>: Bessel functions of <em>x</em> of the first kind of order 0</li> 383<li> <kbd>j1(</kbd><em>x</em><kbd>)</kbd>: Bessel functions of <em>x</em> of the first kind of order 1</li> 384<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> 385<li> <kbd>ln(</kbd><em>x</em><kbd>)</kbd>: natural logarithm function</li> 386<li> <kbd>log(</kbd><em>x</em><kbd>)</kbd>: logarithm base 10</li> 387<li> <kbd>logtwo(</kbd><em>x</em><kbd>)</kbd>: logarithm base 2</li> 388<li> <kbd>ln(</kbd><em>x</em><kbd>)</kbd>: natural logarithm</li> 389<li> <kbd>max(</kbd><em>x</em>, <em>y</em><kbd>)</kbd>: maximum of <em>x</em> and <em>y</em></li> 390<li> <kbd>min(</kbd><em>x</em>, <em>y</em><kbd>)</kbd>: minimum of <em>x</em> and <em>y</em></li> 391<li> <kbd>mod(</kbd><em>x</em>, <em>y</em><kbd>)</kbd>: floating-point remainder function</li> 392<li> <kbd>pow(</kbd><em>x</em>,<em>y</em><kbd>)</kbd>: power function (<em>x<sup>y</sup></em>)</li> 393<li> <kbd>rand()</kbd>: value uniformly distributed over the interval [0.0, 1.0) with a 2 to the 128th-1 period</li> 394<li> <kbd>round()</kbd>: round to integral value, regardless of rounding direction</li> 395<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> 396<li> <kbd>sin(</kbd><em>x</em><kbd>)</kbd>: sine function</li> 397<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> 398<li> <kbd>sinh(</kbd><em>x</em><kbd>)</kbd>: hyperbolic sine function</li> 399<li> <kbd>sqrt(</kbd><em>x</em><kbd>)</kbd>: square root function</li> 400<li> <kbd>tan(</kbd><em>x</em><kbd>)</kbd>: tangent function</li> 401<li> <kbd>tanh(</kbd><em>x</em><kbd>)</kbd>: hyperbolic tangent function</li> 402<li> <kbd>trunc(</kbd><em>x</em><kbd>)</kbd>: round to integer, towards zero</li> 403</ul> 404 405<p>The expression semantics include these rules:</p> 406 407<ul> 408<li>symbols are case insensitive</li> 409<li>only one ternary conditional (e.g. x ? y : z) per statement</li> 410<li>statements are assignments or the final expression to return</li> 411<li>an assignment starts a statement, it is not an operator</li> 412<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> 413<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> 414<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> 415</ul> 416 417 418</div> 419 420<h3>Source Images</h3> 421<div class="doc-section"> 422 423<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> 424 425<p>As an example, we form an image by averaging the first image and third images:</p> 426 427<p class='crt'><span class="crtprompt"> $magick> </span><span class='crtin'>convert image1.jpg image2.jpg image3.jpg -fx "(u+u[2])/2.0" image.jpg</span></p> 428<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> 429 430<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> 431 432<p class='crt'><span class="crtprompt"> $magick> </span><span class='crtin'>convert -channel red logo: -flop logo: -resize "20%" -fx "(u+v)/2" image.jpg</span></p> 433<div class="image"> 434 <a href="/images/logo-sm-flop.png"><img src="/images/logo-sm-flop.png" width="128" height="96" alt="logo-sm-flop.png" /></a> 435 <a href="/images/logo-sm.png"><img src="/images/logo-sm.png" width="128" height="96" alt="logo-sm.png" /></a> 436<img style="margin-top:38px; margin-bottom:38px;" src="/images/right.gif" width="20" height="20" alt="==>" /> 437 <a href="/images/logo-sm-fx.png"><img src="/images/logo-sm-fx.png" width="128" height="96" alt="logo-sm-fx.png" /></a> 438</div> 439 440 441</div> 442 443<h3>Accessing Pixels</h3> 444<div class="doc-section"> 445 446<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> 447 448<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> 449 450<pre class="text"> 451 p[-1].g green value of pixel to the immediate left of the current pixel 452 p[-1,-1].r red value of the pixel diagonally left and up from current pixel 453</pre> 454 455<p>To specify an absolute position, use braces, rather than brackets.</p> 456 457<pre class="text"> 458 p{0,0}.r red value of the pixel in the upper left corner of the image 459 p{12,34}.b blue pixel value at column number 12, row 34 of the image 460</pre> 461 462<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> 463 464<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> 465 466</div> 467 468<h3>Apply an Expression to Select Image Channels</h3> 469<div class="doc-section"> 470 471<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> 472 473<p class='crt'><span class="crtprompt"> $magick> </span><span class='crtin'>convert alpha.png beta.png -channel red -fx "(u.g+v.g)/2" gamma.png</span></p> 474</div> 475 476<h3>Results</h3> 477<div class="doc-section"> 478 479<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> 480 481<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> 482 483 484<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> 485 486<p class='crt'><span class="crtprompt"> $magick> </span><span class='crtin'>convert xc:'rgb(25%,50%,75%)' rose: -colorspace rgb \ <br/> 487 -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/> 488 Red channel of NW corner of image # 1 is 0.188235</span></p> 489<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> 490 491</div> 492</div> 493 494</div> 495 496<div id="linkbar"> 497 <span id="linkbar-west"> </span> 498 <span id="linkbar-center"> 499 <a href="http://www.imagemagick.org/discourse-server/">Discourse Server</a> • 500 <a href="http://www.imagemagick.org/MagickStudio/scripts/MagickStudio.cgi">Studio</a> 501 </span> 502 <span id="linkbar-east"> </span> 503 </div> 504 <div class="footer"> 505 <span id="footer-west">© 1999-2011 ImageMagick Studio LLC</span> 506 <span id="footer-east"> <a href="http://www.imagemagick.org/script/contact.php">Contact the Wizards</a></span> 507 </div> 508 <div style="clear: both; margin: 0; width: 100%; "></div> 509 <script type="text/javascript"> 510 var _gaq = _gaq || []; 511 _gaq.push(['_setAccount', 'UA-17690367-1']); 512 _gaq.push(['_trackPageview']); 513 514 (function() { 515 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 516 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 517 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 518 })(); 519 </script> 520</body> 521</html> 522