Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial use, ONLY.

    For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net.

    If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment.

    Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at: http://www.imagemagick.org/script/license.php

MULTIGRADIENT


Creates either a linear or radial gradient image with two or more stops to specify colors and locations along the gradient direction.

Download Script

last modified: September 26, 2017



USAGE: multigradient [-w width] [-h height] [-s stops] [-t type] [-d direction] [-c center] [-r radii] outfile
USAGE: multigradient [-help]

-w ... width ....... width of desired output image; default=256
-h ... height ...... height of desired output image; default=256
-s ... stops ....... stops; space separate list of pairs of color and
.................... percent location along the gradient enclosed in double
.................... quotes; default="white black"
-t ... type ........ type of gradient; choices are linear, circle or ellipse;
.................... default=linear
-d ... direction ... direction of gradient; angle or sides or corners;
.................... default=to-bottom for linear and closest-side for circle
.................... or ellipse; angles are measured in degrees clockwise
.................... from the zeroangle direction; -360<=angle<=360
-c ... center ...... x and y center coordinates for ellipse or circle;
.................... pair of comma separated floats>=0;
.................... default=(width-2)/2,(height-1)/2
-r ... radii ....... x and y radii for ellipse or circle;
.................... pair of comma separated floats>=0;
.................... default is determined by distance from center to
.................... closest-side
-z ... zeroangle ... zero angle direction for type=linear; choices are:
.................... to-top or to-right; default=to-top

PURPOSE: To create either a linear or radial gradient image with two or more stops to specify colors and locations along the gradient direction.

DESCRIPTION: RADIALGRADIENT creates either a linear or radial gradient image with two or more stops to specify colors and locations along the gradient direction. Linear gradients may be oriented at any rotation angle or towards any side or corner. A radial gradient may be either an ellipse or constrained to a circle. Directions include: closest-side, furthest-side, closest-corner, or furthest corner. Colors may contain partial transparency and allow any valid IM color specification, including color names, rgb values or hex values. This script attempts to simulate many of the features of CSS style gradients.

ARGUMENTS:

-w width ... WIDTH of desired output image. The default=256.

-h height ... HEIGHT of desired output image. The default=256.

-s stops ... STOPS are a space separate list of pairs of colors and percent locations along the gradient enclosed in double quotes. The first and last percent location may be left off and are then assumed to be 0 and 100 (percent). The default="white black" or "white 0 black 100".

-t type ... TYPE of gradient. The choices are: linear, circle or ellipse. The default=linear.

-d direction ... DIRECTION of gradient. For type=linear, direction may be either an angle in degrees measured clockwise from the zeroangle in the range of -360 to 360 or alternately, direction may be any one of the following: to-top, to-right, to-bottom, to-left, to-topright, to-bottomright, to-bottomleft or to-topleft for linear. For type=ellipse or circle, direction may be one of the following: closest-side, furthest-side, closest-corner, furthest-corner. For type=linear, the default is to-bottom for zeroangle=to-top and the default is to-right for zeroangle=to-right. For ellipse or circle the default=closest-side.

-c center ... x and y CENTER coordinates for ellipse or circle expressed as a comma separate pair of non-negative floats. The default=(width-2)/2,(height-1)/2.

-r radii ... x and y RADII for ellipse or circle expressed as a comma separate pair of non-negative floats. The default is determined by distance from the gradient center to the closest-side.

-z zeroangle ... ZEROANGLE is direction where angle=0 for type=linear. The choices are: to-top or to-right. The default=to-top

REFERENCE: http://dev.w3.org/csswg/css-images-3/

CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk.


EXAMPLES


Example 1 - Grayscale Linear Gradient

Arguments:
(defaults)
or
-w 256 -h 256 -s "white black"
or
-w 256 -h 256 -s "white 0 black 100"
or
-w 256 -h 256 -s "white black" -t linear -d 180
or
-w 256 -h 256 -s "white black" -t linear -d to-bottom
or
-w 256 -h 256 -s "black white" -t linear -d to-top
or
-w 256 -h 256 -s "black white" -t linear -d 0
Arguments:
-w 256 -h 256 -s "black white"
or
-w 256 -h 256 -s "black 0 white 100"
or
-w 256 -h 256 -s "black white" -t linear -d 180
or
-w 256 -h 256 -s "black white" -t linear -d to-bottom
or
-w 256 -h 256 -s "white black" -t linear -d to-top
or
-w 256 -h 256 -s "white black" -t linear -d 0


Example 2 - Two-Tone Linear Gradient

Arguments:
-w 256 -h 256 -s "red blue"
Arguments:
-w 256 -h 256 -s "red none"


Example 3 - Multiple Stops Linear Gradient - Variation In Rotation Angle

Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t linear -d XX
where
XX is 30 degree increments from 0 to 330 combined as an animation


Example 3 - Multiple Stops Linear Gradient - To Sides

Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t linear -d to-top
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t linear -d to-right
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t linear -d to-bottom
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t linear -d to-left


Example 4 - Multiple Stops Linear Gradient - To Corners

Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t linear -d to-topright
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t linear -d to-bottomright
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t linear -d to-bottomleft
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t linear -d to-topleft


Example 4 - Multiple Stops Circular Gradient

Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t circular -d closest-side
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t circular -d furthest-side
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t circular -d closest-corner
or since centered
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t circular -d furthest-corner
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t circular -d closest-side -c "100,100"
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t circular -d furthest-side -c "100,100"
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t circular -d closest-corner -c "100,100"
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t circular -d furthest-corner -c "100,100"


Example 4 - Multiple Stops Elliptical Gradient

Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t ellipse -d closest-side
or since centered
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t ellipse -d furthest-side
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t ellipse -d closest-corner
or since centered
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t ellipse -d furthest-corner
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t ellipse -d closest-side -c "100,100"
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t ellipse -d furthest-side -c "100,100"
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t ellipse -d closest-corner -c "100,100"
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t ellipse -d furthest-corner -c "100,100"
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t ellipse -c "100,100" -r "50,100"
Arguments:
-w 400 -h 200 -s "red yellow 20 cyan 50 magenta 70 blue" -t ellipse -c "100,100" -r "100,50"


What the script does is as follows:

  • creates an appropriate size and oriented linear or radial grayscale gradient
  • creates a 1D image of appended gradient sections according to the color stop pairs
  • applies the 1D colored gradient to the 2D grayscale gradient using -clut