Fred's ImageMagick Scripts



 

 

GRID


Superimposes a set of horizontal and/or vertical grid lines on an image.

Download Script

last modified: May 30, 2008



USAGE: grid [-s spacing] [-c color] [-t thickness] [-o opacity] infile outfile
USAGE: grid [-h or -help]

-s ...... spacing ..... x,y spacing between grid lines; default=16,16 or 16;
....................... second number is defaulted to the first
-c ...... color ....... color of grid lines; default="black"
-t ...... thickness ... thickness of grid lines; 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 horizontal and/or vertical grid lines on an image.

DESCRIPTION: GRID superimposes a set of horizontal and/or vertical grid lines on an image. Parameters are available to select the grid line color, thickness and opacity.

ARGUMENTS:

-s spacing ... SPACING specifies the horizontal (x) and vertical (y) grid offset between lines. Spacing must be provided as integer values. If the second value is left off, then it will be set identical to the first. If only vertical lines are desired, set the horizontal (x) spacing larger than the width of the image. If only horizontal lines are desired, set the vertical (y) spacing larger than the height of the image. The default=8. Note: if you want the bottom and/or right grid line to show, then the image dimension(s) must be a multiple of the grid spacing plus 1.

-c color ... COLOR is the color of the grid lines. Any valid IM color specification is allowed. Be sure to color values in double quotes. The default="black".

-t thickness ... THICKNESS is the grid line thickness. Values are positive integers. 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


Grid Lines Superimposed On Image

Original Image
(size 128x128)

arguments:
none
(-s 16)

arguments:
-o 0.3

arguments:
-s 16,130

arguments:
-s 130,16

arguments:
-c white



What the script does is as follows:

  • Draws a set of horizontal and/or vertical 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.

  • drawstr="M 0,0 L 127,0 M 0,16 L 127,16 M 0,32 L 127,32 \
    M 0,48 L 127,48 M 0,64 L 127,64 M 0,80 L 127,80 M 0,96 L 127,96 \
    M 0,112 L 127,112 M 0,128 L 127,128 M 0,0 L 0,127 M 16,0 L 16,127 \
    M 32,0 L 32,127 M 48,0 L 48,127 M 64,0 L 64,127 M 80,0 L 80,127 \
    M 96,0 L 96,127 M 112,0 L 112,127 M 128,0 L 128,127"
  • convert $infile -fill none -stroke black -strokewidth 1 \
    -draw "stroke-opacity 1 path '$drawstr'" $outfile