Fred's ImageMagick Scripts



 

 

ANGLEGRADIENT


Creates a gradient effect at a specific orientation angle.

Download Script

last modified: February 04, 2010



USAGE: anglegradient widthxheight [-a angle] [-c color ] outfile
USAGE: anglegradient [-h or -help]

widthxheight ................... widthxheight of gradient image
-a .............. angle......... orientational angle for gradient;
................................ degrees rotation from a vertical in
................................ clockwise direction; default=0;
................................ or nw,ne,se,sw for diagonal
-c .............. colors........ gradient coloration; any valid
................................ hyphenated color pair involving
................................ opaque colors or "none"

PURPOSE: To create a gradient effect at a specific orientation angle.

DESCRIPTION: ANGLEGRADIENT creates a gradient effect at a specific orientation angle.

ARGUMENTS:

widthxheight ... WIDTHxHEIGHT are the dimensions of the gradient image.

-a angle ... ANGLE is the angle for the gradient coloration in degrees. Values must be greater than or equal to 0 and less than or equal to 360. Alternately, values of nw, ne, se, or sw may be specified to have the diagonal angle automatically, computed. For angle=0, the gradient will have the first color at the top and the second color at the bottom. As the gradient-angle is increased, the gradient rotates clockwise. The default=0.

-c colors ... COLORS is any valid hyphenated IM color pair including opaquecolor-opaquecolor, opaquecolor-none or none-opaquecolor for a transition from one opaque color to another or to transparency. If no color pair is specified, then the normal grayscale gradient will be generated. For angle=0, the first color will be at the top and the second color at the bottom of the gradient image.

NOTE: This script requires IM 6.4.2-6 or higher due to the use of -distort SRT.

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


Angle Gradient

Arguments:
128x128

Arguments:
128x128 -a 30

Arguments:
128x128 -a 30 -c red-blue

Arguments:
128x128 -a 30 -c red-none

Arguments:
256x128 -a 30 -c red-blue

Arguments:
256x128 -a 30 -c red-none



What the script does is as follows:

  • Creates a normal gradient of the specified color
  • Rotates it using -distort SRT

This is equivalent to the following IM commands for red-blue gradient

  • maxdim=`convert xc: -format "%[fx:max($width,$height)]" info:`
  • convert -size ${maxdim}x${maxdim} gradient: \
    -distort SRT "$angle" \
    -gravity center -crop ${width}x${height}+0+0 +repage \
    -contrast-stretch 0 \
    +level-colors "blue-red" \
    $outfile