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

RADIALGRADIENT


Creates a radial gradient image.

Download Script

last modified: April 25, 2015



USAGE: radialgradient WidthxHeight [-d diameters] [-c center] [-C colors] outfile
USAGE: radialgradient [-h or -help]

....... WidthxHeight .... width and height of desired output image
-d .... diameters ....... x and y diameters of radial gradient;
......................... pair of comma separated floats>=0;
......................... default=Width,Height
-c .... center .......... x and y center coordinates for radial gradient;
......................... pair of comma separated floats>=0;
......................... default=Width/2,Height/2
-C .... colors .......... inner and outer colors for radial gradient;
......................... hyphen separate pair of IM colors;
......................... default="black-white"; be sure to enclose them
......................... in quotes.

PURPOSE: To create a radial gradient image.

DESCRIPTION: RADIALGRADIENT create a radial gradient image. The user can specify the x and y diameters and the x and y center coordinates. Nominally, the center will be black and increase in brightness to white at the radii (half diameters) from the center.

ARGUMENTS:

WidthxHeight ... WIDTHxHEIGHT is the desired sized of the output image.

-d diameters ... DIAMETERS are the x and y diameters for the radial gradient. Values are floats>=0. The default=Width,Height.

-c center ... CENTER is the x and y center coordinates for the radial gradient. Values are floats>=0. The default=Width/2,Height/2.

-C colors ... COLORS are the inner and outer limit colors of the radial gradient. They are specified as a hyphen separate pair of valid IM colors. The default="black-white". Be sure to enclose them in quotes.

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


Simple Radial Gradients

Arguments:
100x100

Arguments:
100x200

Arguments:
100x200 -d 100,100 -c 50,50

Arguments:
100x200 -d 50,100 -c 50,50



Other Radial Gradients

Arguments:
100x200 -C "white-black"

Arguments:
100x200 -C "red-blue"

Arguments:
100x200 -C "red-none"



What the script does is as follows:

  • Creates a 1D squared linear gradient in x and scales to WidthxHeight
  • Creates a 1D squared linear gradient in y and scales to WidthxHeight
  • Adds the two images and takes the square root
  • Optionally colorizes with +level-colors

This is equivalent to the following IM commands for a simple black-white radial gradient.

  • ww=`echo "$size" | cut -dx -f 1`
  • hh=`echo "$size" | cut -dx -f 2`
  • dx=`echo $diameters | cut -d, -f 1`
  • dy=`echo $diameters | cut -d, -f 2`
  • cx=`echo $offsets | cut -d, -f 1`
  • cy=`echo $offsets | cut -d, -f 2`
  • convert \
    \( -size ${ww}x1 xc: -fx "xx=(i-$cx)/($dx/2); xx^2" -scale ${ww}x${hh}! \) \
    \( -size 1x${hh} xc: -fx "yy=(j-$cy)/($dy/2); yy^2" -scale ${ww}x${hh}! \) \
    -compose plus -composite -evaluate pow 0.5 \
    $outfile