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

BORDEREFFECTS


Creates various dispersion-like effects in the border of an image.

Download Script

last modified: September 26, 2017



USAGE: bordereffects [-s size] [-d density] [-c curviness] [-g granularity] [-b bgcolor] [-p pad] [-r reseed] infile outfile
USAGE: bordereffects [-h or -help]

-s .... size ............ size of border; integer>0; default=5
-d .... density ......... density or frequency of detail; float>=1;
......................... default=5
-c .... curviness ....... curviness in border features; float>=0;
......................... default=5
-g .... granularity ..... pixelization size factor; integer>0; default=1
-b .... bgcolor ......... background color; any valid IM color is allowed;
......................... default=white
-p .... pad ............. border pad or buffer; integer>=0; default=2
-r .... reseed .......... forced seed value; integer>0;
......................... default will randomly change seed

PURPOSE: To create various dispersion-like effects in the border of an image.

DESCRIPTION: BORDEREFFECTS creates various dispersion-like effects in the border of an image. Effects include a random grainly pattern, a smooth but curved outline and a detailed curvy pattern. The border effect will occur inside the image, so that the image size does not change.

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 5.

-d density ... DENSITY is the frequency of detail in the border. Values are floats greater than or equal to 1. The default=5.

-c curviness ... CURVINESS is the curviness in the border features. Larger values create more curviness. Values are floats greater than or equal to 0. The default=5.

-g granularity ... Granularity is the base grain size or pixelization size used to create the detail in the border. Values are integers greater than 0. The default is 1.

-b bgcolor ... BGCOLOR is the background color to use in the border. Any valid IM color may be used. The default is white.

-p pad ... PAD is the pad size of constant color around the perimeter of the border. Values are integers greater or equal to 0. The default=2.

-r reseed ... RESEED is forced seed value to use for randomization. This permits the pattern to be repeated. The default is to change the seed value randomly each time the script is run, thus causing somewhat different patterns each time the script is run.

NOTE: For IM prior to 6.4.8-5, the script uses -fx and may be a little slow.

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 5 -d 5 -c 5 -g 1 -p 2 -b white

Arguments:
-s 5 -d 5 -c 1 -g 1 -p 2 -b white

Arguments:
-s 5 -d 5 -c 5 -g 1 -p 2 -b white

Arguments:
-s 5 -d 5 -c 5 -g 1 -p 2 -b white

Arguments:
-s 2 -d 2 -c 2 -g 1 -p 2 -b white

Arguments:
-s 2 -d 1 -c 5 -g 1 -p 2 -b white

Arguments:
-s 2 -d 1 -c 2 -g 1 -p 2 -b white

Arguments:
-s 2 -d 5 -c 0 -g 1 -p 2 -b white

Arguments:
-s 1 -d 1 -c 2 -g 1 -p 2 -b white

Arguments:
-s 1 -d 1 -c 1 -g 1 -p 2 -b white

Arguments:
-s 1 -d 2 -c 1 -g 1 -p 2 -b white

Arguments:
-s 1 -d 1 -c 0 -g 1 -p 2 -b white

Arguments:
-s 2 -d 5 -c 0 -g 3 -p 2 -b white

Arguments:
-s 3 -d 5 -c 0 -g 3 -p 2 -b white

Arguments:
-s 5 -d 5 -c 0 -g 3 -p 2 -b white

 

 


What the script does is as follows:

  • Creates a white image with black border
  • Creates a random, pixelized, blurred displacement map
  • Applies the displacement map to the b/w image using a trig function
  • Applies the randomly displaced mask to composite the image with the background color

This is equivalent to the following IM commands for the case of granularity=1

  • ww=`convert $infile -format "%[fx:w]" info:`
  • hh=`convert $infile -format "%[fx:h]" info:`
  • newsize=`convert xc: -format "%[fx:$size+$pad]" info:`
  • newsize2=`convert xc: -format "%[fx:2*$newsize]" info:`
  • ww2=`convert xc: -format "%[fx:($ww-$newsize2)]" info:`
  • hh2=`convert xc: -format "%[fx:($hh-$newsize2)]" info:`
  • convert -size ${ww2}x${hh2} xc:white \
    -bordercolor black -border ${newsize}x${newsize} $tmp0
  • [ "$curviness" = "0" ] && blur="-blur 0x${curviness}"
  • [ "$reseed" = "" ] && seed="-seed $reseed"
  • convert -size ${ww}x${hh} xc: $seed +noise Random \
    $scale \
    $blur \
    -fx intensity -contrast-stretch 0% \
    $tmp1
  • convert $tmp0 $tmp1 -monitor \
    -fx "xx=i+$size*sin($density*v*2*pi); yy=j+$size*cos($density*v*2*pi); u.p{xx,yy}" \
    $tmp2
  • convert \( -size ${ww}x${hh} xc:"$bgcolor" \) $infile $tmp2 \ -compose over -composite $outfile