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.

GRID


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

Download Script

last modified: December 15, 2018



USAGE: grid [-s spacing] [-d displace] [-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
-d ...... displace .... x,y displacement (offset) of the first grid lines in x and y;
....................... default=0,0 or 0; 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 distance between lines. Spacing must be provided as non-negative 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=16. 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.

-d displace ... DISPLACE specifies the horizontal (x) and vertical (y) grid offset from the top left corner for the first grid line. Distance must be provided as non-negative integer values. If the second value is left off, then it will be set identical to the first. If you do not want the first grid line at x=0 and/or y=0, then specify the displace value as spacing-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