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

PERFORATIONS


Applies film-like perforations to two opposite edges of an image.

Download Script

last modified: September 26, 2017



USAGE: perforations [-n number] [-s size] [-p position] [-b border] infile outfile
USAGE: perforations [-h or -help]

-n ... number ..... number of perforations; integer>0; default=8
-s ... size ....... size of perforations as percentage of smaller image
................... dimension; 0<float<=15; default=6
-p ... position ... position of perforations; choices are: TB (for top/bottom
................... edges or LR (for left/right edges); default is along the
................... edges corresponding to the larger image dimension
-b ... border ..... border type; choices are: black, burned, faded or none;
................... default=black

PURPOSE: To apply film-like perforations to two opposite edges of an image.

DESCRIPTION: PERFORATIONS applies film-like perforations to two opposite edges of an image. Various border types may be selected.

ARGUMENTS:

-n number ... NUMBER of perforations. Values are integers>0. The default=8.

-s size ... SIZE of perforations as percentage of smaller image dimension. Values are 0<floats<=15. The default=6.

-p position POSITION of perforations. The choices are: TB (for top/bottom edges or LR (for left/right edges). The default is along the edges corresponding to the larger image dimension.

-b border ... BORDER type. The choices are: black (b), aged (a), faded (f) or none (n). The default=black. Note: border=faded fades to transparent.

Requirements: IM 6.5.9.3 or higher due to the use of 1D morphology blur for border=aged or faded.

References:
http://motion.kodak.com/motion/uploadedFiles/US_plugins_acrobat_en_motion_newsletters_filmEss_11_Film_Specs.pdf
http://en.wikipedia.org/wiki/Film_perforations
http://askville.amazon.com/Sprockets-frame-film/AnswerViewer.do?requestId=1796570

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 -- Top/Bottom Edges
(source)

Original

Arguments:
-n 8 -s 6 -p tb -b black

Arguments:
-n 8 -s 6 -p tb -b aged

Arguments:
-n 8 -s 6 -p tb -b faded

Arguments:
-n 8 -s 6 -p tb -b none



Example 2 -- Left/Right Edges
(source)

Original

Arguments:
-n 8 -s 6 -p lr -b black

Arguments:
-n 8 -s 6 -p lr -b aged

Arguments:
-n 8 -s 6 -p lr -b faded

Arguments:
-n 8 -s 6 -p lr -b none



What the script does is as follows for border=black at the top/bottom edges:

  • Creates a white round rectangle in a black background and
    tiles it out to make a row/column of the size of an edge of the image
  • Composites the tiled row/column at two opposite edges of the image

This is equivalent to the following IM commands

  • ww=`convert $infile -ping -format "%w" info:`
  • hh=`convert $infile -ping -format "%h" info:`
  • mind=`convert xc: -format "%[fx:min($ww,$hh)]" info:`
  • ht=`convert xc: -format "%[fx:round($mind*$size/100)]" info:`
  • wd=`convert xc: -format "%[fx:round($ratio*$ht)]" info:`
  • rd=`convert xc: -format "%[fx:round($rndfact*($wd+$ht)/2)]" info:`
  • wd1=$((wd-1))
  • ht1=$((ht-1))
  • cellw=`convert xc: -format "%[fx:floor($ww/$number)]" info:`
  • cellh=`convert xc: -format "%[fx:floor(2*$ht)]" info:`
  • tilew=`convert xc: -format "%[fx:$number*$cellw]" info:`
  • gravity1="north"
  • gravity2="south"
  • midw=$ww
  • midh=$((hh-2*cellh))
  • flipping="-flip"
  • appending="-append"
  • blurring="blur:0x${cellh}+90"
  • shaving="0x2"
  • convert -size ${wd}x${ht} xc:black -fill white \
    -draw "roundrectangle 0,0 $wd1,$ht1 $rd,$rd" -alpha off \
    -gravity center -background black -extent ${cellw}x${cellh} \
    -write mpr:cell +delete -size ${tilew}x${cellh} tile:mpr:cell \
    -extent ${ww}x${cellh} $tmpA2
  • convert $tmpA1 $tmpA2 \( +clone $flipping \) \
    \( -clone 0 -clone 1 -gravity $gravity1 -compose over -composite \) \
    -delete 0,1 +swap -gravity $gravity2 -compose over -composite $outfile