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.

STRIPES


Adds a striped border to an image.

Download Script

last modified: January 19, 2022



USAGE: stripes [-t thickness] [-m mode] [-c1 color1] [-c2 color2] [-a angle] [-r rounding] infile outfile
USAGE: stripes [-help]

-t .... thickness ... thickness of each of two stripes composing the border;
..................... integer>=0; default=10
-m .... mode ........ mode of striped border; choices are: inside or outside;
..................... default=inside
-c1 ... color1 ...... color of first stripe; default=red
-c2 ... color2 ...... color of second stripe; default=blue
-a .... angle ....... angle of stripes; -180<=integer<=180; default=45
-r .... rounding .... rounding of corners; integer>=0; default=0

PURPOSE: Adds a striped border to an image.

DESCRIPTION: STRIPES adds a striped border to an image. The angle of the stripes may be specified along with the thickness and rounding of the border. The border may be specified either inside or outside the input image.

ARGUMENTS:

-t thickness ... THICKNESS of each of two stripes composing the border. Values are integers>=0. The default=10.

-m mode ... MODE of striped border. The choices are: inside (i) or outside (o). The default is inner.

-c1 color1 ... COLOR1 is the color of the first stripe. Any valid Imagemagick opaque color may be specified. The default=red.

-c2 color2 ... COLOR2 is the color of the second stripe. Any valid Imagemagick opaque color may be specified. The default=blue.

-a angle ... ANGLE of stripes in degrees. Values are -180<=integer<=180. The default=45.

-r rounding ... ROUNDING of the corners. Values are integers>=0. The default=0.

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 Image
( source)

 

Arguments:
-m inside -r 20

 

Arguments:
-m outside -r 20


What the script does is as follows:

  • Creates a stripe of each color and appends and writes to mpr:/li>
  • Tiles the pair of stripes to a large size
  • Rotates the tiled image and then center crops to the size of the input
  • Creates a white image of the size of the input with a black border
  • Applies rounding to each corner of the white image with black border
  • Puts the white and black bordered image into the alpha channel of the cropped tiles image
  • Composites the input image in the center of the tiled border image
  • Saves the result

This is equivalent to the following IM commands no border is used.

  • ww=`convert -ping $infile -format "%w" info:`
  • hh=`convert -ping $infile -format "%h" info:`
  • if [ "$mode" = "outside" ]; then
    wd=$((ww+4*thickness))
    ht=$((hh+4*thickness))
    wd2=$ww
    ht2=$hhd
    shaving=""
    method="over"
    elif [ "$mode" = "inside" ]; then
    wd=$ww
    ht=$hh
    wd2=$((ww-4*thickness))
    ht2=$((hh-4*thickness))
    thickness2=$((2*thickness))
    shaving="-shave ${thickness2}x${thickness2}"
    method="dst_over"
    fi
  • diag=`convert xc: -format "%[fx:round(hypot($wd,$ht))]" info:`
  • convert \
    -size ${diag}x${thickness} xc:"$color1" xc:"$color2" -append \
    -write mpr:stripe +delete \
    -size ${diag}x${diag} tile:mpr:stripe +repage \
    -virtual-pixel white -distort SRT $angle +repage \
    -gravity center -crop ${wd}x${ht}+0+0 +repage \
    \( -size ${wd}x${ht} xc:white \
    -size ${wd2}x${ht2} xc:black \
    -gravity center -compose over -composite \
    \( -size ${rounding}x${rounding} xc:black \
    -draw "fill white circle ${rounding},${rounding} ${rounding},0" \
    -write mpr:arc +delete \) \
    \( mpr:arc \) -gravity northwest -composite \
    \( mpr:arc -flip \) -gravity southwest -composite \
    \( mpr:arc -flop \) -gravity northeast -composite \
    \( mpr:arc -rotate 180 \) \
    -gravity southeast -composite \) \
    -alpha off -compose copy_opacity -composite \
    \( $tmpA1 $shaving \) -gravity center -compose $method -composite \
    "$outfile"