blob: 5e0ccac67d6c4ac84f9ccae076dedf4eb9dddb1a [file] [log] [blame]
Cristy594d2772015-11-15 10:47:42 -05001
2
3
4
Cristy882d9f42015-10-29 16:48:39 -04005<!DOCTYPE html>
6<html lang="en">
7<head>
Cristybbb69882017-06-30 10:13:32 -04008 <meta charset="utf-8" />
9 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
Cristy6549abb2016-11-10 08:25:55 -050010 <title>Image Gradients @ ImageMagick</title>
Cristybbb69882017-06-30 10:13:32 -040011 <meta name="application-name" content="ImageMagick" />
12 <meta name="description" content="ImageMagick® is a software suite to create, edit, compose, or convert bitmap images. It can read and write images in a variety of formats (over 200) including PNG, JPEG, JPEG-2000, GIF, WebP, Postscript, PDF, and SVG. Use ImageMagick to resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves." />
13 <meta name="application-url" content="https://www.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-2017 ImageMagick Studio LLC" />
23 <meta name="distribution" content="Global" />
24 <meta name="magick-serial" content="P131-S030410-R485315270133-P82224-A6668-G1245-1" />
Cristy912a9222016-06-17 15:37:28 -040025 <meta name="google-site-verification" content="_bMOCDpkx9ZAzBwb2kF3PRHbfUUdFj2uO8Jd1AXArz4" />
Cristybbb69882017-06-30 10:13:32 -040026 <link href="https://www.imagemagick.org/script/gradient.html" rel="canonical" />
27 <link href="../images/wand.png" rel="icon" />
28 <link href="../images/wand.ico" rel="shortcut icon" />
29 <link href="css/magick.css" rel="stylesheet" />
Cristy882d9f42015-10-29 16:48:39 -040030</head>
31<body>
Cristybbb69882017-06-30 10:13:32 -040032<div class="magick-masthead">
Cristy882d9f42015-10-29 16:48:39 -040033 <div class="container">
Cristy6549abb2016-11-10 08:25:55 -050034 <script async="async" src="http://localhost/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle"
Cristy594d2772015-11-15 10:47:42 -050035 style="display:block"
36 data-ad-client="ca-pub-3129977114552745"
37 data-ad-slot="6345125851"
38 data-ad-format="auto"></ins>
Cristy882d9f42015-10-29 16:48:39 -040039 <script>
40 (adsbygoogle = window.adsbygoogle || []).push({});
41 </script>
Cristy49380402017-06-29 11:24:55 -040042 <nav class="nav magick-nav">
43 <a class="nav-link " href="../index.html">Home</a>
44 <a class="nav-link " href="download.html">Download</a>
45 <a class="nav-link " href="command-line-tools.html">Tools</a>
46 <a class="nav-link " href="command-line-processing.html">Command-line</a>
47 <a class="nav-link " href="resources.html">Resources</a>
48 <a class="nav-link " href="develop.html">Develop</a>
49 <a class="nav-link " href="https://www.imagemagick.org/script/search.php">Search</a>
50 <a class="nav-link float-right" href="https://www.imagemagick.org/discourse-server/">Community</a>
Cristy882d9f42015-10-29 16:48:39 -040051 </nav>
52 </div>
53</div>
54<div class="container">
55<div class="magick-header">
56
Cristye93be682015-11-26 09:07:51 -050057<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>
Cristy882d9f42015-10-29 16:48:39 -040058
Cristye93be682015-11-26 09:07:51 -050059<p>For a linear gradient, the operator is either:</p>
Cristy882d9f42015-10-29 16:48:39 -040060
Cristy49380402017-06-29 11:24:55 -040061<pre><code>
Cristy882d9f42015-10-29 16:48:39 -040062gradient:
Cristye93be682015-11-26 09:07:51 -050063gradient:color1-color2
Cristy49380402017-06-29 11:24:55 -040064</code></pre>
Cristy882d9f42015-10-29 16:48:39 -040065
Cristye93be682015-11-26 09:07:51 -050066<p> The for a radial gradient, the operator is either:</p>
Cristy882d9f42015-10-29 16:48:39 -040067
Cristy49380402017-06-29 11:24:55 -040068<pre><code>
Cristy882d9f42015-10-29 16:48:39 -040069radial-gradient:
Cristye93be682015-11-26 09:07:51 -050070radial-gradient:color1-color2
Cristy49380402017-06-29 11:24:55 -040071</code></pre>
Cristy882d9f42015-10-29 16:48:39 -040072
Cristye93be682015-11-26 09:07:51 -050073<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>
Cristy882d9f42015-10-29 16:48:39 -040074
Cristye93be682015-11-26 09:07:51 -050075<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>
Cristy882d9f42015-10-29 16:48:39 -040076
Cristy6549abb2016-11-10 08:25:55 -050077<p>Gradient colors may be any valid color defined per <a href="https://www.imagemagick.org/script/color.html" target="_blank">https://www.imagemagick.org/script/color.html</a>. The named colors of black/white/grayXX are non-linear gray gradients; whereas gray(XX[%]) is a linear gray gradient. For Unix systems, enclose rgb(a) and hex colors in quotes. Use double quotes, if using variables for the values.</p>
Cristy882d9f42015-10-29 16:48:39 -040078
Cristye93be682015-11-26 09:07:51 -050079<p>Here is an example linear gradient:</p>
Cristy882d9f42015-10-29 16:48:39 -040080
Cristy49380402017-06-29 11:24:55 -040081<pre><code>
Cristye93be682015-11-26 09:07:51 -050082convert -size 256x256 gradient: linear_gradient.png
83convert -size 256x256 gradient:white-black linear_gradient.png
Cristy49380402017-06-29 11:24:55 -040084</code></pre>
Cristy92721ca2017-06-10 13:26:30 -040085<p><img src="../images/gradients/linear_gradient.png" width="256" height="256" /></p>
Cristy882d9f42015-10-29 16:48:39 -040086
Cristye93be682015-11-26 09:07:51 -050087<p>If you want a radial gradient, try:</p>
Cristy882d9f42015-10-29 16:48:39 -040088
Cristy49380402017-06-29 11:24:55 -040089<pre><code>
Cristye93be682015-11-26 09:07:51 -050090convert -size 256x256 radial-gradient: radial_gradient.png
91convert -size 256x256 radial-gradient:white-black radial_gradient.png
Cristy49380402017-06-29 11:24:55 -040092</code></pre>
Cristy92721ca2017-06-10 13:26:30 -040093<p><img src="../images/gradients/radial_gradient.png" width="256" height="256" /></p>
Cristy882d9f42015-10-29 16:48:39 -040094
Cristye93be682015-11-26 09:07:51 -050095<p>As of IM 6.9.2.5, gradients have been enhanced through the use of several -defines.</p>
Cristy882d9f42015-10-29 16:48:39 -040096
Cristy49380402017-06-29 11:24:55 -040097<table class="table table-sm table-striped">
Cristy882d9f42015-10-29 16:48:39 -040098 <tr>
Cristybc232422016-11-22 07:46:18 -050099 <td><code>-define gradient:vector=<var>x1</var>,<var>y1</var>, <var>x2</var>,<var>y2</var></code></td>
Cristy882d9f42015-10-29 16:48:39 -0400100 <td>Specifies the direction of the linear gradient going from vector1
Cristye93be682015-11-26 09:07:51 -0500101 (x1,y1) to vector2 (x2,y2). Color1 (fromColor) will be located at vector
102 position x1,y1 and color2 (toColor) will be located at vector position
Cristy882d9f42015-10-29 16:48:39 -0400103 x2,y2.</td>
104 </tr>
105
106 <tr>
107 <td><code>-define gradient:center=<var>x</var>,<var>y</var></code></td>
108 <td>Specifies the coordinates of the center point for the radial gradient.
109 The default is the center of the image.</td>
110 </tr>
111
112 <tr>
113 <td><code>-define gradient:radii=<var>x</var>,<var>y</var></code></td>
114 <td>Specifies the x and y radii of the gradient. If the x radius and the y
Cristye93be682015-11-26 09:07:51 -0500115 radius are equal, the shape of the radial gradient will be a circle. If
116 they differ, then the shape will be an ellipse. The default values are the
Cristy882d9f42015-10-29 16:48:39 -0400117 maximum of the half width and half height of the image.</td>
118 </tr>
119
120 <tr>
Cristye93be682015-11-26 09:07:51 -0500121 <td><code>-define gradient:angle=<var>angle in degrees</var></code></td>
122 <td>For a linear gradient, this specifies the direction of the gradient
123 going from color1 to color2 in a clockwise positive manner relative to
124 north (up). For a radial gradient, this specifies the rotation of the
125 gradient in a clockwise positive manner from its normal X-Y
Cristy882d9f42015-10-29 16:48:39 -0400126 orientation.</td>
127 </tr>
Cristye93be682015-11-26 09:07:51 -0500128
129 <tr>
130 <td><code>-define gradient:bounding-box=<var>width</var>x<var>height</var>+<var>x</var>+<var>y</var></code></td>
131 <td>Limits the gradient to a larger or smaller region than the image
132 dimensions. If the region defined by the bounding box is smaller than the
133 image, then color1 will be the color of the background.</td>
134 </tr>
Cristy882d9f42015-10-29 16:48:39 -0400135</table>
136
137
Cristye93be682015-11-26 09:07:51 -0500138<p>We also support two convenience defines for setting the linear gradient direction and the radial gradient shape.</p>
Cristy882d9f42015-10-29 16:48:39 -0400139
Cristy49380402017-06-29 11:24:55 -0400140<table class="table table-sm table-striped">
Cristy882d9f42015-10-29 16:48:39 -0400141 <tr>
142 <td><code>-define gradient:direction=<em>{NorthWest, North, Northeast, West, East, SouthWest, South, SouthEast}</em></code></td>
Cristye93be682015-11-26 09:07:51 -0500143 <td>Specifies the direction of the linear gradient towards the
Cristy882d9f42015-10-29 16:48:39 -0400144 top/bottom/left/right or diagonal corners.</td>
145 </tr>
146
147 <tr>
Cristybc232422016-11-22 07:46:18 -0500148 <td><code>-define gradient:extent=<em>{Circle, Diagonal, Ellipse, Maximum, Minimum}</em></code></td>
Cristye93be682015-11-26 09:07:51 -0500149 <td>Specifies the shape of an image centered radial gradient. Circle and
Cristy882d9f42015-10-29 16:48:39 -0400150 Maximum draw a circular radial gradient even for rectangular shaped images
151 of radius equal to the larger of the half-width and half-height of the
152 image. The Circle and Maximum options are both equivalent to the default
153 radial gradient. The Minimum option draws a circular radial gradient
154 even for rectangular shaped images of radius equal to the smaller of the
155 half-width and half-height of the image. The Diagonal option draws a
156 circular radial gradient even for rectangular shaped images of radius equal
157 to the half-diagonal of the image. The Ellipse options draws an elliptical
158 radial gradient for rectangular shaped images of radii equal to half the
159 width and half the height of the image.</td>
160 </tr>
161</table>
162
Cristye93be682015-11-26 09:07:51 -0500163<p>Examples</p>
Cristy882d9f42015-10-29 16:48:39 -0400164
Cristye93be682015-11-26 09:07:51 -0500165<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>
Cristy882d9f42015-10-29 16:48:39 -0400166
Cristy49380402017-06-29 11:24:55 -0400167<pre><code>
Cristye93be682015-11-26 09:07:51 -0500168convert -size 256x128 -define gradient:direction=north gradient:black-white linear_gradient_default.png
169convert -size 256x128 -define gradient:angle=0 gradient:black-white linear_gradient_default.png
Cristy49380402017-06-29 11:24:55 -0400170</code></pre>
Cristy92721ca2017-06-10 13:26:30 -0400171<p><img src="../images/gradients/linear_gradient_default.png" width="256" height="128" /></p>
Cristy882d9f42015-10-29 16:48:39 -0400172
Cristye93be682015-11-26 09:07:51 -0500173<p>The equivalent of </p>
Cristy882d9f42015-10-29 16:48:39 -0400174
Cristy49380402017-06-29 11:24:55 -0400175<pre><code>
Cristye93be682015-11-26 09:07:51 -0500176convert -size 128x256 gradient: -rotate 90 linear_gradient_east.png
Cristy49380402017-06-29 11:24:55 -0400177</code></pre>
Cristy882d9f42015-10-29 16:48:39 -0400178
Cristye93be682015-11-26 09:07:51 -0500179<p>can be generate by either of the following (or by reversing the direction and swapping color1 and color2):</p>
Cristy882d9f42015-10-29 16:48:39 -0400180
Cristy49380402017-06-29 11:24:55 -0400181<pre><code>
Cristye93be682015-11-26 09:07:51 -0500182convert -size 256x128 -define gradient:direction=east gradient:black-white linear_gradient_east.png
183convert -size 256x128 -define gradient:angle=90 gradient:black-white linear_gradient_east.png
Cristy49380402017-06-29 11:24:55 -0400184</code></pre>
Cristy92721ca2017-06-10 13:26:30 -0400185<p><img src="../images/gradients/linear_gradient_east.png" width="256" height="128" /></p>
Cristy882d9f42015-10-29 16:48:39 -0400186
187
Cristye93be682015-11-26 09:07:51 -0500188<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>
Cristy882d9f42015-10-29 16:48:39 -0400189
190
Cristy49380402017-06-29 11:24:55 -0400191<pre><code>
Cristye93be682015-11-26 09:07:51 -0500192convert -size 256x128 radial-gradient:black-white radial_gradient_maximum.png
193convert -size 256x128 -define gradient:radii=128,128 radial-gradient:black-white radial_gradient_maximum.png
Cristy49380402017-06-29 11:24:55 -0400194</code></pre>
Cristy92721ca2017-06-10 13:26:30 -0400195<p><img src="../images/gradients/radial_gradient_maximum.png" width="256" height="128" /></p>
Cristye93be682015-11-26 09:07:51 -0500196
Cristy49380402017-06-29 11:24:55 -0400197<pre><code>
Cristye93be682015-11-26 09:07:51 -0500198convert -size 256x128 -define gradient:extent=minimum radial-gradient:black-white radial_gradient_minimum.png
199convert -size 256x128 -define gradient:radii=64,64 radial-gradient:black-white radial_gradient_minimum.png
Cristy49380402017-06-29 11:24:55 -0400200</code></pre>
Cristy92721ca2017-06-10 13:26:30 -0400201<p><img src="../images/gradients/radial_gradient_minimum.png" width="256" height="128" /></p>
Cristye93be682015-11-26 09:07:51 -0500202
Cristy49380402017-06-29 11:24:55 -0400203<pre><code>
Cristye93be682015-11-26 09:07:51 -0500204convert -size 256x128 -define gradient:extent=diagonal radial-gradient:black-white radial_gradient_diagonal.png
Cristy49380402017-06-29 11:24:55 -0400205</code></pre>
Cristy92721ca2017-06-10 13:26:30 -0400206<p><img src="../images/gradients/radial_gradient_diagonal.png" width="256" height="128" /></p>
Cristye93be682015-11-26 09:07:51 -0500207
Cristy49380402017-06-29 11:24:55 -0400208<pre><code>
Cristye93be682015-11-26 09:07:51 -0500209convert -size 256x128 -define gradient:extent=ellipse radial-gradient:black-white radial_gradient_ellipse.png
210convert -size 256x128 -define gradient:radii=128,64 radial-gradient:black-white radial_gradient_ellipse.png
Cristy49380402017-06-29 11:24:55 -0400211</code></pre>
Cristy92721ca2017-06-10 13:26:30 -0400212<p><img src="../images/gradients/radial_gradient_ellipse.png" width="256" height="128" /></p>
Cristye93be682015-11-26 09:07:51 -0500213
Cristy49380402017-06-29 11:24:55 -0400214<pre><code>
Cristye93be682015-11-26 09:07:51 -0500215convert -size 256x256 -define gradient:radii=128,64 -define gradient:angle=45 radial-gradient:black-white radial_gradient_ellipse_angle45.png
Cristy49380402017-06-29 11:24:55 -0400216</code></pre>
Cristy92721ca2017-06-10 13:26:30 -0400217<p><img src="../images/gradients/radial_gradient_ellipse_angle45.png" width="256" height="256" /></p>
Cristye93be682015-11-26 09:07:51 -0500218
Cristy882d9f42015-10-29 16:48:39 -0400219</div>
220
221 <footer class="magick-footer">
222 <p><a href="support.html">Donate</a>
223 <a href="sitemap.html">Sitemap</a>
224 <a href="links.html">Related</a>
Cristye0779712016-07-30 17:25:22 -0400225 <a href="security-policy.html">Security</a>
Cristy882d9f42015-10-29 16:48:39 -0400226 <a href="architecture.html">Architecture</a>
227</p>
228 <p><a href="gradient.html#">Back to top</a>
229 <a href="http://pgp.mit.edu:11371/pks/lookup?op=get&amp;search=0x89AB63D48277377A">Public Key</a>
Cristy6549abb2016-11-10 08:25:55 -0500230 <a href="https://www.imagemagick.org/script/contact.php">Contact Us</a></p>
Cristyfe36f992016-12-29 20:24:13 -0500231 <p><small>© 1999-2017 ImageMagick Studio LLC</small></p>
Cristy882d9f42015-10-29 16:48:39 -0400232 </footer>
233</div><!-- /.container -->
234
Cristyb7f455a2017-03-03 19:30:34 -0500235 <script src="https://localhost/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
Cristy1f1f3a02016-06-01 07:25:42 -0400236 <script src="../js/magick.html"></script>
Cristy882d9f42015-10-29 16:48:39 -0400237</body>
238</html>
Cristybbb69882017-06-30 10:13:32 -0400239<!-- Magick Cache 30th June 2017 09:55 -->