v7.1.2-34 Latest Stable Release

Image Gradients

Create smooth color transitions with ImageMagick gradients. Learn how to generate linear, radial, and custom gradients for backgrounds, overlays, and image effects with precise control.

quickstart.sh
# Install via your favorite Package Manager
$ brew install imagemagick
# Convert PNG to WebP with compression
$ magick input.png -quality 85 output.webp
# Resize image maintaining aspect ratio
$ magick input.jpg -resize 800x600^ output.jpg

An image gradient creates a gradual blend between two colors formed into a shape that is linear, circular, or elliptical.

Gradient colors may be any valid color defined per https://imagemagick.org/color/. The named colors of black/white/grayXX and gray(XX[%]) are non-linear gray. For Linux systems, enclose rgb(a) and hex colors in quotes. Use double quotes if using variables for the values.

Linear Gradients

For a linear gradient, the operator is either:

gradient:
gradient:fromColor
gradient:fromColor-toColor

The default fromColor is white and the toColor is black unless overridden, e.g., gradient:gray returns a gradient from gray to black. The default linear gradient has fromColor at the top of the image and toColor at the bottom of the image.

Here is an example linear gradient:

magick -size 256x256 gradient: linear_gradient.png
magick -size 256x256 gradient:white-black linear_gradient.png
linear gradient
linear_gradient.png

Radial Gradients

For a radial gradient, the operator is either:

radial-gradient:
radial-gradient:fromColor-toColor

Similarly, the default for a radial gradient has fromColor at the center of the image and toColor at the boundary of the image.

If you want a radial gradient, try:

magick -size 256x256 radial-gradient: radial_gradient.png
magick -size 256x256 radial-gradient:white-black radial_gradient.png
radial gradient
radial_gradient.png

Non-Linear Grayscale Gradients

If you want non-linear grayscale gradients, then add -colorspace RGB -colorspace gray before saving the output. For example:

magick -size 256x256 gradient: linear_gradient.png
magick -size 256x256 gradient:white-black -colorspace RGB -colorspace gray linear_linear_gradient.png
magick -size 256x256 radial-gradient: radial_gradient.png
magick -size 256x256 radial-gradient:white-black -colorspace RGB -colorspace gray linear_radial_gradient.png

Gradient Defines & Options

Gradients are affected by these primary defines:

Define Parameter Description
-define gradient:vector=x1,y1, x2,y2 Specifies the direction of the linear gradient going from vector1 (x1,y1) to vector2 (x2,y2). fromColor is located at vector position x1,y1 and toColor is located at vector position x2,y2.
-define gradient:center=x,y Specifies the coordinates of the center point for the radial gradient. The default is the center of the image.
-define gradient:radii=x,y Specifies the x and y radii of the gradient. If equal, the shape is a circle; if they differ, an ellipse. Default values are the maximum of the half width and half height.
-define gradient:angle=angle in degrees For linear gradients, specifies direction from fromColor to toColor clockwise relative to north. For radial gradients, specifies rotation clockwise from normal X-Y orientation.
-define gradient:bounding-box=widthxheight+x+y Limits the gradient to a larger or smaller region than image dimensions. If smaller, fromColor is the background color.

ImageMagick also supports two convenience defines for setting linear gradient direction and radial gradient shape:

Convenience Define Description
-define gradient:direction={NorthWest, North, Northeast, West, East, SouthWest, South, SouthEast} Specifies the direction of the linear gradient towards top/bottom/left/right or diagonal corners.
-define gradient:extent={Circle, Diagonal, Ellipse, Maximum, Minimum} Specifies the shape of an image-centered radial gradient (Circle/Maximum = circular with radius equal to larger half-dimension; Minimum = smaller half-dimension; Diagonal = half-diagonal; Ellipse = radii equal to half-width and half-height).

Examples

The default linear gradient may also be generated in any of the following ways (or by reversing direction and swapping colors):

magick -size 256x128 -define gradient:direction=north gradient:black-white linear_gradient_default.png
magick -size 256x128 -define gradient:angle=0 gradient:black-white linear_gradient_default.png
linear gradient default
linear_gradient_default.png

The equivalent of:

$ magick -size 128x256 gradient: -rotate 90 linear_gradient_east.png

can be generated by either of the following:

magick -size 256x128 -define gradient:direction=east gradient:black-white linear_gradient_east.png
magick -size 256x128 -define gradient:angle=90 gradient:black-white linear_gradient_east.png
radial gradient east
linear_gradient_east.png

Examples of radial gradients going from black in the center to white at the boundary for maximum, minimum, diagonal, ellipse, and 45-degree rotated ellipse follow below:

Maximum / Circle / Default
magick -size 256x128 radial-gradient:black-white radial_gradient_maximum.png
magick -size 256x128 -define gradient:radii=128,128 radial-gradient:black-white radial_gradient_maximum.png
radial gradient maximum
Minimum Extent
magick -size 256x128 -define gradient:extent=minimum radial-gradient:black-white radial_gradient_minimum.png
magick -size 256x128 -define gradient:radii=64,64 radial-gradient:black-white radial_gradient_minimum.png
radial gradient minimum
Diagonal Extent
$ magick -size 256x128 -define gradient:extent=diagonal radial-gradient:black-white radial_gradient_diagonal.png
radial gradient diagonal
Ellipse Extent
magick -size 256x128 -define gradient:extent=ellipse radial-gradient:black-white radial_gradient_ellipse.png
magick -size 256x128 -define gradient:radii=128,64 radial-gradient:black-white radial_gradient_ellipse.png
radial gradient ellipse
Rotated Ellipse (45°)
$ magick -size 256x256 -define gradient:radii=128,64 -define gradient:angle=45 radial-gradient:black-white radial_gradient_ellipse_angle45.png
radial gradient ellipse angle 45