1 2 3 4 5<!DOCTYPE html> 6<html lang="en"> 7<head> 8 <meta charset="utf-8" /> 9 <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1,shrink-to-fit=no" /> 10 <title>ImageMagick - Image Gradients</title> 11 <meta name="application-name" content="ImageMagick" /> 12 <meta name="description" content="Use ImageMagick® to create, edit, compose, and convert bitmap images. Resize an image, crop it, change its shades and colors, add captions, and more." /> 13 <meta name="application-url" content="https://imagemagick.org" /> 14 <meta name="generator" content="PHP" /> 15 <meta name="keywords" content="image, gradients, ImageMagick, PerlMagick, image processing, image, photo, software, Magick++, OpenMP, convert" /> 16 <meta name="rating" content="GENERAL" /> 17 <meta name="robots" content="INDEX, FOLLOW" /> 18 <meta name="generator" content="ImageMagick Studio LLC" /> 19 <meta name="author" content="ImageMagick Studio LLC" /> 20 <meta name="revisit-after" content="2 DAYS" /> 21 <meta name="resource-type" content="document" /> 22 <meta name="copyright" content="Copyright (c) 1999-2020 ImageMagick Studio LLC" /> 23 <meta name="distribution" content="Global" /> 24 <meta name="magick-serial" content="P131-S030410-R485315270133-P82224-A6668-G1245-1" /> 25 <meta property='og:url' content='../' /> 26 <meta property='og:title' content='ImageMagick' /> 27 <meta property='og:image' content='../images/logo.png' /> 28 <meta property='og:type' content='website' /> 29 <meta property='og:site_name' content='ImageMagick' /> 30 <meta property='og:description' content="Convert, Edit, or Compose Bitmap Images" /> 31 <meta name="google-site-verification" content="_bMOCDpkx9ZAzBwb2kF3PRHbfUUdFj2uO8Jd1AXArz4" /> 32 <link href="../www/gradient.html" rel="canonical" /> 33 <link href="../images/wand.png" rel="icon" /> 34 <link href="../images/wand.ico" rel="shortcut icon" /> 35 <link href="assets/magick.css" rel="stylesheet" /> 36</head> 37<body> 38 <nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark"> 39 <a class="navbar-brand" href="../index.html"><img class="d-block" id="icon" alt="ImageMagick" width="32" height="32" src="../images/wand.ico"/></a> 40 <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsMagick" aria-controls="navbarsMagick" aria-expanded="false" aria-label="Toggle navigation"> 41 <span class="navbar-toggler-icon"></span> 42 </button> 43 44 <div class="navbar-collapse collapse" id="navbarsMagick" style=""> 45 <ul class="navbar-nav mr-auto"> 46 <li class="nav-item "> 47 <a class="nav-link" href="../index.html">Home <span class="sr-only">(current)</span></a> 48 </li> 49 <li class="nav-item "> 50 <a class="nav-link" href="download.html">Download</a> 51 </li> 52 <li class="nav-item "> 53 <a class="nav-link" href="command-line-tools.html">Tools</a> 54 </li> 55 <li class="nav-item "> 56 <a class="nav-link" href="command-line-processing.html">Command-line</a> 57 </li> 58 <li class="nav-item "> 59 <a class="nav-link" href="resources.html">Resources</a> 60 </li> 61 <li class="nav-item "> 62 <a class="nav-link" href="develop.html">Develop</a> 63 </li> 64 <li class="nav-item"> 65 <a class="nav-link" target="_blank" href="https://imagemagick.org/discourse-server/">Community</a> 66 </li> 67 </ul> 68 <form class="form-inline my-2 my-lg-0" action="https://imagemagick.org/script/search.php"> 69 <input class="form-control mr-sm-2" type="text" name="q" placeholder="Search" aria-label="Search"> 70 <button class="btn btn-outline-success my-2 my-sm-0" type="submit" name="sa">Search</button> 71 </form> 72 </div> 73 </nav> 74 <div class="container"> 75 <script async="async" src="http://localhost/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" 76 style="display:block" 77 data-ad-client="ca-pub-3129977114552745" 78 data-ad-slot="6345125851" 79 data-full-width-responsive="true" 80 data-ad-format="horizontal"></ins> 81 <script> 82 (adsbygoogle = window.adsbygoogle || []).push({}); 83 </script> 84 85 </div> 86 87 <main class="container"> 88 <div class="magick-template"> 89<div class="magick-header"> 90 91<p class="lead magick-description">An image gradient creates a gradual blend between two colors formed into a shape that is linear, circular, or ellipical.</p> 92 93<p>For a linear gradient, the operator is either:</p> 94 95<pre class="highlight"><code>gradient: 96gradient:color1-color2 97</code></pre> 98 99<p> The for a radial gradient, the operator is either:</p> 100 101<pre class="highlight"><code>radial-gradient: 102radial-gradient:color1-color2 103</code></pre> 104 105<p> In the above, color1 is the fromColor and color2 is the toColor, as described in more detail below. The default is white for color1 and black for color2, i.e., white-black.</p> 106 107<p>The default for a linear gradient has color1 at the top of the image and color2 at the bottom of the image. Similarly, the default for a radial gradient has color1 at the center of the image and color2 at the boundary of the image.</p> 108 109<p>Gradient colors may be any valid color defined per <a href="../www/color.html" target="_blank">../www/color.html</a>. The named colors of black/white/grayXX and gray(XX[%]) are non-linear gray. For Unix systems, enclose rgb(a) and hex colors in quotes. Use double quotes, if using variables for the values.</p> 110 111<p>Here is an example linear (as opposed to radial) gradient:</p> 112 113<pre class="highlight"><code>magick -size 256x256 gradient: linear_gradient.png 114magick -size 256x256 gradient:white-black linear_gradient.png 115</code></pre> 116<p><img src="../images/gradients/linear_gradient.png" width="256" height="256" /></p> 117 118<p>If you want a radial gradient, try:</p> 119 120<pre class="highlight"><code>magick -size 256x256 radial-gradient: radial_gradient.png 121magick -size 256x256 radial-gradient:white-black radial_gradient.png 122</code></pre> 123<p><img src="../images/gradients/radial_gradient.png" width="256" height="256" /></p> 124 125<p>If you want non-linear grayscale gradients, then add -colorspace RGB -colorspace gray 126before saving the output. For example:<p> 127 128<pre class="highlight"><code>magick -size 256x256 gradient: linear_gradient.png 129magick -size 256x256 gradient:white-black -colorspace RGB -colorspace gray linear_linear_gradient.png 130</code></pre> 131 132<pre class="highlight"><code>magick -size 256x256 radial-gradient: radial_gradient.png 133magick -size 256x256 radial-gradient:white-black -colorspace RGB -colorspace gray linea_radial_gradient.png 134</code></pre> 135 136<p>As of IM 6.9.2.5, gradients have been enhanced through the use of several -defines.</p> 137 138<table class="table table-sm table-striped"> 139 <tr> 140 <td><code>-define gradient:vector=<var>x1</var>,<var>y1</var>, <var>x2</var>,<var>y2</var></code></td> 141 <td>Specifies the direction of the linear gradient going from vector1 142 (x1,y1) to vector2 (x2,y2). Color1 (fromColor) will be located at vector 143 position x1,y1 and color2 (toColor) will be located at vector position 144 x2,y2.</td> 145 </tr> 146 147 <tr> 148 <td><code>-define gradient:center=<var>x</var>,<var>y</var></code></td> 149 <td>Specifies the coordinates of the center point for the radial gradient. 150 The default is the center of the image.</td> 151 </tr> 152 153 <tr> 154 <td><code>-define gradient:radii=<var>x</var>,<var>y</var></code></td> 155 <td>Specifies the x and y radii of the gradient. If the x radius and the y 156 radius are equal, the shape of the radial gradient will be a circle. If 157 they differ, then the shape will be an ellipse. The default values are the 158 maximum of the half width and half height of the image.</td> 159 </tr> 160 161 <tr> 162 <td><code>-define gradient:angle=<var>angle in degrees</var></code></td> 163 <td>For a linear gradient, this specifies the direction of the gradient 164 going from color1 to color2 in a clockwise positive manner relative to 165 north (up). For a radial gradient, this specifies the rotation of the 166 gradient in a clockwise positive manner from its normal X-Y 167 orientation.</td> 168 </tr> 169 170 <tr> 171 <td><code>-define gradient:bounding-box=<var>width</var>x<var>height</var>+<var>x</var>+<var>y</var></code></td> 172 <td>Limits the gradient to a larger or smaller region than the image 173 dimensions. If the region defined by the bounding box is smaller than the 174 image, then color1 will be the color of the background.</td> 175 </tr> 176</table> 177 178 179<p>We also support two convenience defines for setting the linear gradient direction and the radial gradient shape.</p> 180 181<table class="table table-sm table-striped"> 182 <tr> 183 <td><code>-define gradient:direction=<em>{NorthWest, North, Northeast, West, East, SouthWest, South, SouthEast}</em></code></td> 184 <td>Specifies the direction of the linear gradient towards the 185 top/bottom/left/right or diagonal corners.</td> 186 </tr> 187 188 <tr> 189 <td><code>-define gradient:extent=<em>{Circle, Diagonal, Ellipse, Maximum, Minimum}</em></code></td> 190 <td>Specifies the shape of an image centered radial gradient. Circle and 191 Maximum draw a circular radial gradient even for rectangular shaped images 192 of radius equal to the larger of the half-width and half-height of the 193 image. The Circle and Maximum options are both equivalent to the default 194 radial gradient. The Minimum option draws a circular radial gradient 195 even for rectangular shaped images of radius equal to the smaller of the 196 half-width and half-height of the image. The Diagonal option draws a 197 circular radial gradient even for rectangular shaped images of radius equal 198 to the half-diagonal of the image. The Ellipse options draws an elliptical 199 radial gradient for rectangular shaped images of radii equal to half the 200 width and half the height of the image.</td> 201 </tr> 202</table> 203 204<p>Examples</p> 205 206<p>The default linear gradient may also be generated in any of the following ways (or by reversing the direction and swapping color1 and color2):</p> 207 208<pre class="highlight"><code>magick -size 256x128 -define gradient:direction=north gradient:black-white linear_gradient_default.png 209magick -size 256x128 -define gradient:angle=0 gradient:black-white linear_gradient_default.png 210</code></pre> 211<p><img src="../images/gradients/linear_gradient_default.png" width="256" height="128" /></p> 212 213<p>The equivalent of </p> 214 215<pre class="highlight"><code>magick -size 128x256 gradient: -rotate 90 linear_gradient_east.png 216</code></pre> 217 218<p>can be generate by either of the following (or by reversing the direction and swapping color1 and color2):</p> 219 220<pre class="highlight"><code>magick -size 256x128 -define gradient:direction=east gradient:black-white linear_gradient_east.png 221magick -size 256x128 -define gradient:angle=90 gradient:black-white linear_gradient_east.png 222</code></pre> 223<p><img src="../images/gradients/linear_gradient_east.png" width="256" height="128" /></p> 224 225 226<p>Examples of radial gradients going from black in the center to white at the boundary for the cases of "maximum/circle/default", "minimum", "diagonal", "ellipse" and 45 degree rotated ellipse, respectively, follow below.</p> 227 228 229<pre class="highlight"><code>magick -size 256x128 radial-gradient:black-white radial_gradient_maximum.png 230magick -size 256x128 -define gradient:radii=128,128 radial-gradient:black-white radial_gradient_maximum.png 231</code></pre> 232<p><img src="../images/gradients/radial_gradient_maximum.png" width="256" height="128" /></p> 233 234<pre class="highlight"><code>magick -size 256x128 -define gradient:extent=minimum radial-gradient:black-white radial_gradient_minimum.png 235magick -size 256x128 -define gradient:radii=64,64 radial-gradient:black-white radial_gradient_minimum.png 236</code></pre> 237<p><img src="../images/gradients/radial_gradient_minimum.png" width="256" height="128" /></p> 238 239<pre class="highlight"><code>magick -size 256x128 -define gradient:extent=diagonal radial-gradient:black-white radial_gradient_diagonal.png 240</code></pre> 241<p><img src="../images/gradients/radial_gradient_diagonal.png" width="256" height="128" /></p> 242 243<pre class="highlight"><code>magick -size 256x128 -define gradient:extent=ellipse radial-gradient:black-white radial_gradient_ellipse.png 244magick -size 256x128 -define gradient:radii=128,64 radial-gradient:black-white radial_gradient_ellipse.png 245</code></pre> 246<p><img src="../images/gradients/radial_gradient_ellipse.png" width="256" height="128" /></p> 247 248<pre class="highlight"><code>conmagickvert -size 256x256 -define gradient:radii=128,64 -define gradient:angle=45 radial-gradient:black-white radial_gradient_ellipse_angle45.png 249</code></pre> 250<p><img src="../images/gradients/radial_gradient_ellipse_angle45.png" width="256" height="256" /></p> 251 252</div> 253 254 </div> 255 </main><!-- /.container --> 256 <footer class="magick-footer"> 257 <p><a href="security-policy.html">Security</a> • 258 <a href="architecture.html">Architecture</a> 259 260 <a href="gradient.html#"><img class="d-inline" id="wand" alt="And Now a Touch of Magick" width="16" height="16" src="../images/wand.ico"/></a> 261 262 <a href="links.html">Related</a> • 263 <a href="sitemap.html">Sitemap</a> 264 <br/> 265 <a href="support.html">Donate</a> • 266 <a href="http://pgp.mit.edu/pks/lookup?op=get&search=0x89AB63D48277377A">Public Key</a> • 267 <a href="https://imagemagick.org/script/contact.php">Contact Us</a> 268 <br/> 269 <small>© 1999-2020 ImageMagick Studio LLC</small></p> 270 </footer> 271 272 <!-- Javascript assets --> 273 <script src="assets/magick.js" crossorigin="anonymous"></script> 274 <script>window.jQuery || document.write('<script src="https://localhost/ajax/libs/jquery/3.4.1/jquery.min.js"><\/script>')</script> 275</body> 276</html> 277<!-- Magick Cache 5th January 2020 12:14 -->