Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial (non-profit) 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

    Please read the Pointers For Use on my home page to properly install and customize my scripts.

ANGLEGRADIENT


Creates a gradient effect at a specific orientation angle.

Download Script

last modified: December 15, 2018



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