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.

POSTAGESTAMP


Applies a perforated postage stamp like border around an image.

Download Script

last modified: December 15, 2018



USAGE: postagestamp [-d diameter] [-s spacing] [-b bordersize] [-B bcolor] [-H hcolor] [-t text] [-f font] [-F fcolor] [-p pointsize] [-g gravity] [-o offsets ] [-m mode] [-O opacity] [-L length] [-S softness] infile outfile

USAGE: postagestamp [-h or -help]

-d ... diameter ..... diameter of half holes as perforation around the
..................... border in pixels; integer>=0; default=10
-s ... spacing ...... spacing between half holes as percent of diameter;
..................... 0<=integer<=100; default=20
-b ... bordersize ... border size; integer>=0; default=15
-B ... bcolor ....... border color; any valid IM color is allowed;
..................... default=white
-H ... hcolor ....... hole color for gaps between perforations; any valid
..................... IM color is allowed; default=none (for transparent)
-t ... text ......... text to place onto the image; default=no text
-f ... font ......... font name or path to font file; default="Arial"
-F ... color ........ font color; any valid IM color is allowed; default=white
-p ... pointsize .... font point size; integer>=0; default=36
-g ... gravity ...... gravity location for placing text; default="southeast"
-o ... offsets ...... offsets for positioning text relative to the gravity
..................... location; comma separate pair of integers>=0;
..................... default="10,30"
-m ... mode ......... shadow mode; choices are: none, center and bottomright;
..................... default=none for no shadow
-O ... opacity ...... shadow opacity; 0<=integer<=100; default=75
-L ... length ....... shadow length (displacement); integer>=0; default=3
-S ... softness ..... shadow softness; integer>=0; default=2

PURPOSE: To apply a perforated postage stamp like border around an image.

DESCRIPTION: POSTAGESTAMP applies a perforated postage stamp like border around an image. The perforation size and border can be adjusted and colored. Optionally, a shadow may be added.

ARGUMENTS:

-d diameter ... DIAMETER of the half holes as perforation around the border in pixels. Values are integers>=0. The default=10.

-s spacing ... SPACING between half hole perforations as percent of the diameter. Values are 0<=integer<=100. The default=20.

-b bordersize ... BORDERSIZE between image and perforations. Values are integers>=0. The default=15.

-B bcolor ... BCOLOR is the border color. Any valid IM color is allowed. The default=white.

-H hcolor ... HCOLOR is the hole color for the gaps between perforations. Any valid IM color is allowed. The default=none (for transparent).

-t text ... TEXT to place onto the image. The default=no text.

-f font ... FONT name or path to font file. The default="Arial".

-F fcolor ... FCOLOR is the font color. Any valid IM color is allowed. The default=white.

-p pointsize ... POINTSIZE is the font point size. Values are integers>=0. The default=36.

-g gravity ... GRAVITY location for placing text. Any valid IM -gravity setting is allowed. The default="southeast".

-o offsets ... OFFSETS for positioning the text relative to the gravity location. Values are a comma separate pair of integers>=0. The default="10,30".

-m mode ... MODE is the shadow mode. The choices are: none (n), center (c) and bottomright (b). The default=none for no shadow.

-O opacity ... OPACITY is the shadow opacity. Values are 0<=integers<=100. The default=75.

-L length ... LENGTH is the shadow length (displacement). Values are integers>=0. The default=3.

-S softness ... SOFTNESS is the shadow softness (blurring amount). Values are integers>=0. The default=2.

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


Example 1 - Variation in Perforation Paramters

Original Image

Arguments:
-t "42¢" -d 10 -s 20 -b 15

Arguments:
-t "42¢" -d 10 -s 40 -b 15

Arguments:
-t "42¢" -d 20 -s 20 -b 30



Example 2 - Variation in Shadow

Original Image

Arguments:
-t "42¢" -d 10 -s 20 -b 15 -m none

Arguments:
-t "42¢" -d 10 -s 20 -b 15 -m center

Arguments:
-t "42¢" -d 10 -s 20 -b 15 -m bottomright



Example 3 - Different Image

Original Image

Arguments:
-t "42¢" -d 10 -s 20 -b 15



What the script does is as follows for a edge sharpened image:

  • Adds padding for a border
  • Creates a small black hole in a white background the size of diameter+2*spacing
  • Tiles it out to an integer size just larger than the image so we get full circles all over
  • Inserts a white region just inside the outer row/column of circles
  • Shaves half the circles away and resize the tiled image to the image plus 2*bordersize
  • Put the previous black/white image into the alpha channel of the image
  • Flattens it over a transparent background color
  • Optionally adds a shadow

This is equivalent to the following IM commands without the shadow:

  • convert -debug exception -quiet -regard-warnings "$infile" +repage "$tmpA1"
  • ww=`convert $infile -format "%w" info:`
  • hh=`convert $infile -format "%h" info:`
  • radius=`convert xc: -format "%[fx:round($diameter/2)]" info:`
  • spacing=`convert xc: -format "%[fx:round($spacing*$diameter/100)]" info:`
  • size=$((diameter+2*spacing))
  • size2=`convert xc: -format "%[fx:round(0.5*$size)]" info:`
  • ww2=$((ww+2*bordersize))
  • hh2=$((hh+2*bordersize))
  • tilewid=`convert xc: -format "%[fx:$size*ceil($ww2/$size)]" info:`
  • tileht=`convert xc: -format "%[fx:$size*ceil($hh2/$size)]" info:`
  • tilewid2=`convert xc: -format "%[fx:$tilewid-2*$size-ceil($spacing)]" info:`
  • tileht2=`convert xc: -format "%[fx:$tileht-2*$size-ceil($spacing)]" info:`
  • offsets=`echo $offsets | tr "," "+"`
  • offsets="+$offsets"
  • convert \ \( $tmpA1 -gravity $gravity -font $font -fill "$fcolor" -pointsize $pointsize -annotate $offsets "$text" \
    -bordercolor "$bcolor" -border $bordersize \) \
    \( -size ${size}x${size} xc:white -fill black \
    -draw "translate $size2,$size2 circle 0,0 0,$radius" -alpha off \
    -write mpr:circle +delete -size ${tilewid}x${tileht} tile:mpr:circle \
    -size ${tilewid2}x${tileht2} xc:white -gravity center -compose over -composite \
    -shave ${size2}x${size2} -resize ${ww2}x${hh2}\! -morphology close diamond:1 \) \
    -gravity center -alpha off -compose copy_opacity -composite -compose over \
    -background "$hcolor" -flatten $outfile