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.

ZOOMROTATETEXT


Creates a zoomed rotating text animation.

Download Script

last modified: August 08, 2018



USAGE: zoomrotatetext -t "text" [-w width ] [-f font] [-c color] [-b bgcolor ] [-r revolutions] [-D direction] [-m mode ] [-p pause] [-F frames] [-d delay] [infile] outfile

USAGE: zoomrotatetext [-h or -help]

-t ... text .......... text string to be used to create the animation; required argument
-w ... width ......... width of text in pixels; integer>0; default=500; height will
...................... be determined from the text height and the amplitude
-f ... font .......... font to use for the text; font name or path to font file;
...................... default=arial
-c ... color ......... color of text; any valid IM color is allowed; default=black
-b ... bgcolor ....... background color for the animation frames; any valid IM color
...................... is allowed; default=white
-r ... revolutions ... number of 360 degree revolutions of the text; integer>0;
...................... default=4
-D ... direction ..... direction of the revolutions; clockwise or counterclockwise;
...................... default=clockwise
-m ... mode .......... mode for the zoom; 1 (zoom out once only), 2 (zoom out,
...................... then zoom in, then zoom out again once only) and 3 (zoom out,
...................... then zoom in, then repeat continuosly); default=2
-p ... pause ......... number of frames to pause between zoom in/out steps with
...................... method 2; integer>0; default=10
-F ... frames ........ number of frames to generate in the animation; integer>0;
...................... default=25
-d ... delay ......... animation delay between frames; integer>0; default=30

infile is optional and will be tiled (or cropped) to replace the background color

PURPOSE: Creates a zoomed and rotating text animation.

DESCRIPTION: ZOOMROTATETEXT creates a zoomed and rotating text animation. The number of revolutions may be specified as well as the mode for the zoom.

ARGUMENTS:

-t text ... TEXT string to be used to create the animation. This is a required argument

-w width ... WIDTH of text in pixels. Values are integers>0. The default=500. The image height will be determined from the text height and the amplitude.

-f font ... FONT to use for the text. Either the font name or path to font file may be used. The default=arial.

-c color ... COLOR of the text. Any valid IM color is allowed. The default=black.

-b bgcolor ... BGCOLOR is the background color for the animation frames. Any valid IM color is allowed. The default=white.

-r revolutions ... REVOLUTIONS is the number of 360 degree revolutions of the text. Values are integers>>0. The default=4.

-D direction ... DIRECTION of the revolutions. Choices are: clockwise (cw) or counterclockwise (ccw). The default=clockwise.

-m mode ... MODE for the zoom. Choices are: 1 (zoom out once only), 2 (zoom out, then zoom in, then zoom out again once only), and 3 (zoom out, then zoom in, then repeat continuosly). The default=2.

-p pause ... Pause is the number of frames to pause between zoom in/out steps with method 2. Values are integers>0. The default=10.

-F frames ... FRAMES is the number of frames to generate in the animation. Values are integers>0. The default=30.

-d delay ... DELAY is the animation delay between frames. Values are integers>0. The default=10.

infile is optional and will be tiled (or cropped) to replace the background color.

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

Arguments:
-t "THIS IS A TEST OF ZOOMROTATE TEXT" -w 400 -f ubuntu -b pink -D cw -m 1 -F 30 -d 10

Arguments:
-t "THIS IS A TEST OF ZOOMROTATE TEXT" -w 400 -f ubuntu -b pink -D ccw -m 1 -F 30 -d 10

Arguments:
-t "THIS IS A TEST OF ZOOMROTATE TEXT" -w 400 -f ubuntu -b pink -D cw -m 2 -F 30 -d 10 -p 10

Arguments:
-t "THIS IS A TEST OF ZOOMROTATE TEXT" -w 400 -f ubuntu -b pink -D ccw -m 2 -F 30 -d 10 -p 10

Arguments:
-t "THIS IS A TEST OF ZOOMROTATE TEXT" -w 400 -f ubuntu -b pink -D cw -m 3 -F 30 -d 10 -p 10

Arguments:
-t "THIS IS A TEST OF ZOOMROTATE TEXT" -w 400 -f ubuntu -b pink -D ccw -m 3 -F 30 -d 10 -p 10



Example 2

Input:

Arguments:
-t "THIS IS A TEST OF ZOOMROTATE TEXT" -w 400 -f ubuntu -b pink -D cw -m 1 -F 30 -d 10

Arguments:
-t "THIS IS A TEST OF ZOOMROTATE TEXT" -w 400 -f ubuntu -b pink -D ccw -m 1 -F 30 -d 10

Arguments:
-t "THIS IS A TEST OF ZOOMROTATE TEXT" -w 400 -f ubuntu -b pink -D cw -m 2 -F 30 -d 10 -p 1-

Arguments:
-t "THIS IS A TEST OF ZOOMROTATE TEXT" -w 400 -f ubuntu -b pink -D ccw -m 2 -F 30 -d 10 -p 1-

Arguments:
-t "THIS IS A TEST OF ZOOMROTATE TEXT" -w 400 -f ubuntu -b pink -D cw -m 3 -F 30 -d 10 -p 1-

Arguments:
-t "THIS IS A TEST OF ZOOMROTATE TEXT" -w 400 -f ubuntu -b pink -D ccw -m 3 -F 30 -d 10 -p 1-



What the script does is as follows:

  • Creates the text image
  • Computes the diagonal distance of the text image
  • Processes the following in loop over zoom and rotation angle
  • Zooms and rotates the image by an amount determined by the number of frames
  • Collects the results for each iteration in a miff: file
  • Converts the miff: file to a GIF aniimation
  • Writes the animation to the output file

This is equivalent to the following IM commands

  • convert -size ${width}x -background "$bgcolor" -fill "$color" -gravity center -font $font label:"$text" $tmp1A
  • WxH=`convert $tmp1A -format "%wx%h" info:`
  • ww=`echo $WxH | cut -dx -f1`
  • hh=`echo $WxH | cut -dx -f2`
  • diag=`convert xc: -format "%[fx:hypot($ww,$hh)]" info:`
  • angle=$((360*revolutions))
  • ang_inc=`convert xc: -format "%[fx:${sgn}$angle/($frames-1)]" info:`
  • zoom_inc=`convert xc: -format "%[fx:(1-$zoomstart)/$frames)]" info:`
  • if [ "$infile" != "" ]; then
    convert -size ${diag}x${diag} tile:"$infile" $tmp2A
    tileproc="$tmp2A +swap -gravity center -compose over -composite"
    else
    tileproc=""
    fi
  • if [ "$mode" = "1" ]; then (
    for ((k=0; k<frames; k++)); do
    rot=`convert xc: -format "%[fx:$k*$ang_inc]" info:
    ` scale=`convert xc: -format "%[fx:$zoomstart+$k*$zoom_inc]" info:`
    convert $tmp1A -background "$bgcolor" -virtual-pixel background \
    +distort SRT "$scale $rot" +repage \
    -gravity center -extent ${diag}x${diag} $tileproc miff:-
    done
    ) | convert -delay $delay - -layers optimize -loop 1 "$outfile"
    elif [ "$mode" = "2" ]; then
    ( for ((k=0; k<frames; k++)); do
    rot=`convert xc: -format "%[fx:$k*$ang_inc]" info:`
    scale=`convert xc: -format "%[fx:$zoomstart+$k*$zoom_inc]" info:`
    convert $tmp1A -background "$bgcolor" -virtual-pixel background \v +distort SRT "$scale $rot" +repage \
    -gravity center -extent ${diag}x${diag} $tileproc miff:-
    done
    ) | convert -delay $delay - -duplicate $pause \
    \( -clone 0-$frames -reverse \) -duplicate $pause \
    \( -clone 0-$frames \) \
    -layers optimize -loop 1 "$outfile"
    elif [ "$mode" = "3" ]; then
    (
    for ((k=0; k<frames; k++)); do
    rot=`convert xc: -format "%[fx:$k*$ang_inc]" info:`
    scale=`convert xc: -format "%[fx:$zoomstart+$k*$zoom_inc]" info:`
    convert $tmp1A -background "$bgcolor" -virtual-pixel background \
    +distort SRT "$scale $rot" +repage \
    -gravity center -extent ${diag}x${diag} $tileproc miff:-
    done
    ) | convert -delay $delay - -duplicate $pause \
    \( -clone 0-$frames -reverse \) -duplicate $pause \
    -layers optimize -loop 0 "$outfile"
    fi