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

BORDERGRID


Creates various various grid effects in the border of an image.

Download Script

last modified: September 26, 2017



USAGE: bordergrid [-s size] [-t thickness] [-o offset] [-d dimension] [-a angle] [-c color] [-b blur] infile outfile
USAGE: bordergrid [-h or -help]

-s .... size ............ size of border; integer>0; default=5
-t .... thickness ....... thickness of image grid lines; integer>0;
......................... default=10
-o .... offset .......... offset between image grid lines (thickness of
......................... background grid lines); integer>0
......................... default=3
-d .... dimension ....... dimension of grid; dimension=1 or 2 for 1D or 2D
......................... default=1
-a .... angle ........... angle of rotation of grid lines; -180<=float<=180;
......................... default=45
-c .... colors .......... one or two comma delimited colors;
......................... if one color, then it will be the background color
......................... alternating with the image;
......................... if two colors, then the first will be the background
......................... color and the second color will be the foreground
......................... color replacing the image.
-b .... blur ............ blur of grid lines; float>=0; default=0

PURPOSE: To create various grid effects in the border of an image.

DESCRIPTION: BORDERGRID creates various grid effects in the border of an image. The grid alternates betweens lines of image and lines of background if only one color is provide. It can also alternates between two colors. The grid can be either 1D or 2D and the grid thickness and spacing can be specified.

ARGUMENTS:

-s size ... SIZE is the size or dimension of the border region. It will be the same size all around the image. Values are integer greater than 0. The default is 10.

-t thickness ... THICKNESS is the thickness of the image grid lines. Values are integers greater than 0. The default=3.

-o offset ... OFFSET is the offset or spacing between the image grid lines. This is equivalent to the thickness of the background grid lines. Values are integers greater than 0. The default=3.

-d dimension ... DIMENSION determines if the grid lines will be 1D or 2D. Values are either 1 or 2. The default is 1.

-a angle ... ANGLE is the angle of rotation of the grid lines (from horizontal for dimension=1). Values are floats between -180 and 180. The default=45.

-c colors ... COLORS one or two comma delimted colors. If only one color is profided, then it will be the background color alternating with the image. If two colors are provided, then the first will be the background color and the second color will be the foreground color replacing the image. The default is white.

-b blur ... BLUR is the amount of blurring of the grid lines. Values are floats greater or equal to 0. The default=0 (no blurring).

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


Original

Arguments:
-s 10 -t 2 -o 4 -d 1 -a 45 -b 0 -c white

Arguments:
-s 10 -t 2 -o 4 -d 1 -a 0 -b 0 -c white

Arguments:
-s 10 -t 2 -o 4 -d 1 -a -45 -b 0 -c white

Arguments:
-s 10 -t 4 -o 2 -d 1 -a 45 -b 0 -c white

Arguments:
-s 10 -t 3 -o 3 -d 1 -a 45 -b 0 -c white

Arguments:
-s 10 -t 3 -o 3 -d 1 -a 45 -b 1 -c white

Arguments:
-s 10 -t 4 -o 1 -d 2 -a -45 -b 0 -c white

Arguments:
-s 10 -t 4 -o 2 -d 2 -a 45 -b 0 -c white

Arguments:
-s 10 -t 4 -o 2 -d 2 -a -45 -b 0 -c white

Arguments:
-s 10 -t 4 -o 2 -d 2 -a 0 -b 0 -c white

Arguments:
-s 10 -t 3 -o 3 -d 2 -a 0 -b 0 -c white

Arguments:
-s 10 -t 3 -o 3 -d 2 -a 45 -b 0 -c white



What the script does is as follows:

  • Creates a black and white grid mask, rotates it,
    crops to original size, covers the middle (less border) with white
  • Composites the image with background using the grid mask

This is equivalent to the following IM commands for the case of 1D grid

  • ww=`identify -ping -format "%w" $infile`
  • hh=`identify -ping -format "%h" $infile`
  • ww1=`convert xc: -format "%[fx:1.5*$ww)]" info:`
  • hh1=`convert xc: -format "%[fx:1.5*$hh)]" info:`
  • ww2=`convert xc: -format "%[fx:($ww-2*$size)]" info:`
  • hh2=`convert xc: -format "%[fx:($hh-2*$size)]" info:`
  • if [ "$blur" = "0" -o "$blur" = "0.0" ]; then
  • smooth=""
  • else
  • smooth="-blur 0x${blur}"
  • fi
  • convert -size ${ww1}x${hh1} xc:none \
    \( -size 1x$thickness xc:white -size 1x$offset xc:black -append \) \
    -channel RGBA -virtual-pixel tile -fx v \
    \( +clone -rotate -90 \) -compose multiply -composite $plarity \
    -background black -rotate $angle -gravity center -crop ${ww}x${hh}+0+0 +repage \
    \( -size ${ww2}x${hh2} xc:white \) -gravity center -compose over -composite \
    $smooth -contrast-stretch 0 \
    $tmp1
  • convert \( -size ${ww}x${hh} xc:"$bgcolor" \) $infile $tmp1 \
    -compose multiply -composite $outfile