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

RADIALGRID


Superimposes circular grid lines on an image.

Download Script

last modified: November 30, 2017



USAGE: radialgrid [-c center] [-m maxradius] [-n numcircles] [-s spacing] [-C color] [-t thickness] [-o opacity] infile outfile
USAGE: radialgrid [-h or -help]

-c ... center ....... x,y coordinate for center of circles; pair of comma separated
..................... floats>=0; default is the image center
-m ... maxradius .... radius of largest circle; float>0 or min, max, diag;
..................... default=half the maximum dimension of the image
-n ... numcircles ... number of circles equally spaced from the center to the
..................... maxradius; integer>0; default=10
-s ... spacing ...... spacing of the circles; float>0; if not specified, the spacing
..................... will be determined from maxradius and numcircles; if specified,
..................... numcircles will be ignored
-C ... color ........ color of grid lines; any valid opaque IM color allowed;
..................... default="black"
-t ... thickness .... thickness of grid lines; integer>0; default=1
-o ... opacity ...... opacity of grid lines opacity between 0.0 and 1.0;
..................... opacity=0 is transparent; opacity=1 is opaque;
..................... default=1

PURPOSE: To superimpose a set of circulare grid lines on an image.

DESCRIPTION: GRID superimposes a set of circular grid lines on an image. Parameters are available to select the grid line color, maximum radius, number of circles, spacing, thickness and opacity.

ARGUMENTS:

-c center ... CENTER is the x,y coordinate for center of circles. Values are a pair of comma separated floats>=0. The default is the image center.

-m maxradius ... MAXRADIUS is the radius of largest circle. Values are either floats>0 or min (minimum), max (maximum), diag (diagonal) half dimension of the image. The default=half the maximum dimension of the image.

-n numcircles ... NUMCIRCLES is the number of equally spaced circles from the center to the maxradius. Values are integers>0. The default=10.

-s spacing ... SPACING of the circles. Values are floats>0. If spacing is not specified, then the spacing will be determined from maxradius and numcircles. If spacing is specified, then numcircles will be ignored.

-C color ... COLOR of the grid lines. Any IM color is allowed, including alpha values. The default=black.

-t thickness ... THICKNESS of the circular grid lines. Values are integers>0. The default=1

-o opacity ... OPACITY is the grid line opacity. Values are non-negative floats between 0.0 and 1.0. The default=1

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


Circular Grid

Original Image

arguments:
-m max

arguments:
-m min

arguments:
-m diag

arguments:
-m max -C red

arguments:
-m max -C red -o 0.3



What the script does is as follows:

  • Draws a set of circular lines on an image

This is equivalent to the following IM commands for the case of
a default set of grid lines spaced 16 pixels apart.

  • width=`convert -ping $tmpA -format "%w" info:`
  • height=`convert -ping $tmpA -format "%h" info:`
  • if [ "$center" = "" ]; then
    centx=`convert xc: -format "%[fx:($width-1)/2]" info:`
    centy=`convert xc: -format "%[fx:($height-1)/2]" info:`
    fi
  • if [ "$maxradius" = "maximum" -o "$maxradius" = "max" ]; then
    maxradius=`convert xc: -format "%[fx:(max($width,$height)-1)/2]" info:`
    elif [ "$maxradius" = "minimum" -o "$maxradius" = "min" ]; then
    maxradius=`convert xc: -format "%[fx:(min($width,$height)-1)/2]" info:`
    elif [ "$maxradius" = "diagonal" -o "$maxradius" = "diag" ]; then
    maxradius=`convert xc: -format "%[fx:(hypot($width,$height)-1)/2 ]" info:`
    else
    test=`expr "$maxradius" : '\([.0-9]*\)'`
    [ $test -eq 1 ] && errMsg "--- MAXRADIUS=$maxradius IS AN INVALID VALUE ---"
    fi
  • if [ "$spacing" = "" ]; then
    spacing=`convert xc: -format "%[fx:$maxradius/$numcircles]" info:`
    else
    numcircles=`convert xc: -format "%[fx:floor($maxradius/$spacing)]" info:`
    fi
  • graphic="translate $centx,$centy stroke-opacity $opacity"
  • for ((i=0; i<=numcircles; i++)); do
    radius=`convert xc: -format "%[fx:$i*$spacing]" info:`
    graphic="$graphic circle 0,0 0,$radius"
    done
  • convert "$infile" -fill none -stroke $color -strokewidth $thickness -draw "$graphic" "$outfile"