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.

SPLICE


Applies a jagged cut and splice effect to an image.

Download Script

last modified: December 15, 2018



USAGE: splice [-t top] [-b bottom] [-g gap] [-v vertices] [-m maxoffset] [-s seed] [-a amount] [-d distance] [-o opacity] [-c color] infile outfile
USAGE: splice [-h or -help]

-t ... top ......... top section height; percent or pixels;
.................... 0<integer<image height (or 100%); default=30%
-b ... bottom ...... bottom section height; percent or pixels;
.................... 0<integer<image height (or 100%); default=30%
-g ... gap ......... gap in pixels between top and bottom sections;
.................... integer>=0; default=10
-v ... vertices .... number of vertices between sides (excluding end points);
.................... integer>=0; default=8
-m ... maxoffset ... maximum vertex pixel offset in the vertical direction;
.................... integer>=0; default=15
-s ... seed ........ random number seed for vertex vertical offsets;
.................... integer>=0; default=300
-a ... amount ...... amount of blur for shadow; integer>=0; default=4
-d ... distance .... shadow distance in pixels; integer>=0; default=4
-o ... opacity ..... shadow opacity; 0<=integer<=100; default=100; if set to
.................... zero, then no shadow will be added
-c ... color ........ background color; any valid IM color is allowed;
.................... default=white

PURPOSE: To apply a jagged cut and splice effect to an image.

DESCRIPTION: SPLICE applies a jagged cut and splice effect to an image. A shadow effect is optional, but applied by default.

ARGUMENTS:

-t top ... TOP is the top section height in percent or pixels. Values are 0<integer<image height (or 100%). The default=30%. Note that the top and bottom sections typically add up to 100% or less of the original image.

-b bottom ... BOTTOM is the bottom section height in percent or pixels. Values are 0<integer<image height (or 100%). The default=30%. Note that the top and bottom sections typically add up to 100% or less of the original image.

-g gap ... GAP is the gap in pixels between the top and bottom sections. Values are integer>=0. The default=10.

-v vertices ... VERTICES are the number of vertices between left and right sides of the image (excluding start and end points). Values are integer>=0. The default=8.

-m maxoffset ... MAXOFFSET is the maximum vertex pixel offset in the vertical direction. Values are integer>=0. The default=15.

-s seed ... SEED is the random number seed for the vertex vertical offsets. Values are integer>=0. The default=300.

-a amount ... AMOUNT is the amount of blur for the shadow. Value are integer>=0. The default=4.

-d distance ... DISTANCE is the shadow distance in pixels. Values are integer>=0. The default=4.

-o opacity ... OPACITY is the shadow opacity. Values are 0<=integer<=100. The default=100. If opacity is set to zero, then no shadow will be added.

-c color ... COLOR is the background color. Any valid IM color is allowed. The default=white.

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

Arguments:
-t 30% -b 30%
(defaults)

Arguments:
-t 30% -b 40%

Arguments:
-t 30% -b 30% -c lightblue



What the script does is as follows:

  • Creates a polygon for the top percent plus the zig-zag vertices
    along the bottom of the top region
  • Creates a white and black mask from the polygon
  • Puts the mask into the alpha channel of the image and crops the
    image for the top section
  • Creates a polygon for the bottom percent plus the zig-zag
    vertices along the top of the bottom region
  • Creates a white and black mask from the polygon
  • Puts the mask into the alpha channel of the image and crops the
    image for the bottom section
  • Applies a -repage to the bottom image so that it matches with
    the top section at the zig-zag and adds the gap amount
  • Optionally adds a shadow
  • Writes the output image

This is equivalent to the following IM commands

  • convert $infile \
    \( -clone 0 -fill black -colorize 100 -fill white -draw "polygon $points_top" \) \
    \( -clone 0 -clone 1 -alpha off -compose copy_opacity -composite -compose over \
    -gravity north -crop ${ww}x${ht}+0+0 +repage \) -delete 1 \
    \( -clone 0 -fill black -colorize 100 -fill white -draw "polygon $points_bottom" \) \
    \( -clone 0 -clone 2 -alpha off -compose copy_opacity -composite -compose over \
    -gravity south -crop ${ww}x${hb}+0+0 +repage -repage $pageoffset \) -delete 2 \
    -delete 0 -background none -layers merge \
    \( -clone 0 -background black -shadow ${opacity}x${amount}+${distance}+${distance} \) \
    +swap -background "$color" -layers merge $outfile