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.

MESMERIZE


Creates a mesmerizing animation from an image.

Download Script

last modified: December 15, 2018



USAGE: mesmerize [-s shape] [-m mode] [-f factor] [-t thick] [-d delay] [-i incr] [-D direction] [-c colors] infile outfile

-s ... shape ....... shape of mesmerizing pattern; choices are: round or
.................... diamond; default=round
-m ... mode ........ mode of mesmerizing pattern; choices are: normal or
.................... split; default=split
-f ... factor ...... scale factor for diamond shape pattern; choices are:
.................... 1 or 2; default=2
-t ... thick ....... thickness of pattern; integer>0; default=40; must be an
.................... integer multiple of the incr to animate smoothly
-d ... delay ....... delay for each frame of animation; integer>=0; default=5
-i ... incr ........ increment of frames in animation; integer>0; default=4
-D ... direction ... direction of motion of animation pattern; choices are:
.................... out or in; default=out
-c ... colors ...... colors of pattern; either "none" or comma separated
.................... pair of opaque colors (names, rgb or hex values);
.................... default="red,blue"; for color images, use "none"

outfile should be of a type that supports multi-frames, such as gif

PURPOSE: To create a mesmerizing animation from an image.

DESCRIPTION: MESMERIZE creates a mesmerizing animation from an image. The image may be binary, grayscale or color. The user may select the shape and colors for the pattern.

ARGUMENTS:

-s shape ... SHAPE of the mesmerizing pattern. The choices are: round (r) or diamond (d). The default=round.

-m mode ... MODE of the mesmerizing pattern. The choices are: normal (n) or split (s). The default=split.

-f factor ... FACTOR is the scale factor for the diamond shape pattern. Values are either 1 or 2. The default=2. Ignored for the round shape.

-t thick ... THICK is the thickness of the pattern. Value are integers>0. The default=40. Thick must be an integer multiple of the incr to animate smoothly.

-d delay ... DELAY for each frame of the animation. Values are integers>=0. The default=5. Provides fine adjustment of the animation speed.

-i incr ... INCR is the increment or skip for the frames in the animation. Values are integers>0. The default=4. Provides coarse adjustment of the animation speed.

-D direction .. DIRECTION of motion of the animation pattern. Choices are: out or in. The default=out.

-c colors ... COLORS of the animation pattern. Values may be either "none" or a comma separated pair of opaque colors (names, rgb or hex values). The default="red,blue". For color images, use "none".

NOTE: The effect on color images will produce an optical illusion whether you see the normal background image and moving stripes of its inverse or vice-versa. Look carefully and you can see either one.

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 - Binary Image - Round Shape

Original

Arguments:
-s round -m split -D out -c "red-blue"
(defaults)
Arguments:
-s round -m split -D in -c "red-blue"
Arguments:
-s round -m normal -D out -c "red-blue"
Arguments:
-s round -m normal -D in -c "red-blue"
Arguments:
-s round -m normal -D in -c "none"


Example 2 - Binary Image - Diamond Shape

Original

Arguments:
-s diamond -m split -D out -f 2 -c "red-blue"
Arguments:
-s diamond -m normal -D out -f 2 -c "red-blue"
Arguments:
-s diamond -m split -D out -f 1 -c "red-blue"
Arguments:
-s diamond -m normal -D out -f 1 -c "red-blue"


Example 3 - Grayscale Image - Round Shape

Original

Arguments:
-s diamond -m split -D out -c "red-blue"


Example 4 - Color Image - Round Shape

Original

Arguments:
-s diamond -m split -D out -c "none"
Arguments:
-s diamond -m split -D out -c "none"


Example 5 - Color Image - Round Shape

Original

Arguments:
-s diamond -m split -D out -c "none"
Arguments:
-s diamond -m normal -D out -c "none"


What the script does is as follows:

  • reads the input image
  • creates a radial-gradient or diamond-shaped gradient image
  • creates a 1D striped Lut image
  • Loops over the image rolling the lut image by increment
  • Applies the lut image to the gradient image
  • Multiplies the image by the modified gradient image
  • Multiplies the negated image by the negated modified gradient image
  • Adds the last two images and applied +level-colors to apply the colors

This is equivalent to the following IM commands.

  • convert -quiet -regard-warnings "$infile" -alpha off +repage $dir/tmpI.mpc
  • wxh=`convert -ping $dir/tmpI.mpc -format "%wx%h" info:`
  • ww=`echo "$wxh" | cut -dx -f1`
  • hh=`echo "$wxh" | cut -dx -f2`
  • maxdim=`convert xc: -format "%[fx:max($ww,$hh)]" info:`
  • hh2=`convert xc: -format "%[fx:round($hh/2)]" info:`
  • maxdim2=$((maxdim*factor))
  • if [ "$thick" = "" ]; then thick=`convert xc: -format "%[fx:$maxdim/32]" info:` fi
  • if [ "$mode" = "normal" ]; then
    yroll=0
    [ "$direction" = "in" -a "$shape" = "round" ] && sign="-"
    [ "$direction" = "out" -a "$shape" = "round" ] && sign="+"
    [ "$direction" = "in" -a "$shape" = "diamond" ] && sign="+"
    [ "$direction" = "out" -a "$shape" = "diamond" ] && sign="-"
    elif [ "$mode" = "split" ]; then
    yroll=$hh2
    [ "$direction" = "in" -a "$shape" = "round" ] && sign="+"
    [ "$direction" = "out" -a "$shape" = "round" ] && sign="-"
    [ "$direction" = "in" -a "$shape" = "diamond" ] && sign="-"
    [ "$direction" = "out" -a "$shape" = "diamond" ] && sign="+"
    fi
  • if [ "$im_version" -ge "06090205" -a "$shape" = "round" ]; then
    convert -size ${ww}x${hh} -define gradient:extent=diagonal radial-gradient:black-white \
    $dir/tmpG.mpc
    elif [ "$shape" = "diamond" ]; then
    convert -size ${maxdim2}x${maxdim2} gradient: \( -clone 0 -rotate 90 \) \
    -solarize 50% -level 0x50% -compose multiply -composite \
    -gravity center -crop ${ww}x${hh}+0+0 +repage $dir/tmpG.mpc
    fi
  • frames=$((thick*2))
  • (
    for ((i=0; i j=$((i/incr))
    echo >&2 "frame=$j"
    convert $dir/tmpI.mpc -write mpr:img +delete \
    \( -size ${thick}x1 xc:black xc:white +append \
    -size ${maxdim}x1 -write mpr:tile +delete tile:mpr:tile -roll ${sign}${i}+0 \) \
    \( $dir/tmpG.mpc -clone 0 -clut -roll +0+$yroll \) \
    -delete 0 \
    \( mpr:img -clone 0 -compose multiply -composite \) \
    \( mpr:img -clone 0 -negate -compose multiply -composite \) \
    -delete 0 \
    -compose over -compose plus -composite miff:-
    done
    ) | convert -delay $delay - $coloring -loop 0 "$outfile"