Here's a complete Windows BAT script using IM7 to accomplish the entire task...
Code: Select all
@echo off
setlocal enabledelayedexpansion
set FONT=courbd.ttf
set POINTS=18
set COUNT=0
for /f "tokens=*" %%L in ( textfile.txt ) do (
magick ^
-font %FONT% ^
-pointsize %POINTS% ^
-kerning 1 ^
label:"\ %%L " ^
label:"XXXXXXXXXX" ^
-colors 16 ^
-crop "%%[fx:round(u.w/(v.w/10))]x1@" ^
-delete -10--1 ^
-background white ^
-coalesce ^
+repage ^
-set delay "%%[fx:t==0||t==(n-1)?75:10]" ^
^( ^
-clone -1,-1,-1,-1 ^
-distort affine "0,%%[fx:(t+1)*h/n] 0,0 " ^
-set delay 10 ^
^) ^
-loop 0 ^
_tmp_!COUNT!.miff
set /a COUNT+=1
)
magick _tmp_*.miff ^
( ^
-clone 0--1 ^
+repage ^
-layers merge ^
) ^
+insert ^
-loop 0 ^
typewriter.gif
del _tmp_*.miff
exit /b
It reads each line of "textfile.txt" and turns each line into an animated GIF letter by letter. It writes each of those results to temporary MIFF files on disk. Then it assembles all the temp files into a single animated GIF that types out each character one at a time, and scrolls from line to line to line.
A couple of caveats...
• Obviously the font must be a monospace font. NOTE: Not all monospace fonts are created equal, so a poorly written font might produce undesirable results.
• The temp files are saved with sequential numbers starting with single digits and no leading zeros, so if the text file has more than ten lines, there might be a problem with wildcard globbing and reading the temp files into the final command in the correct order. I haven't checked so I'm not sure about this.
• Because of the way Windows and ImageMagick handle certain characters, any exclamation points in the text file must be escaped with a caret "^", and any double quotes in the text file must be escaped with a backslash "\". I haven't tested this extensively, but there are probably other characters that require special handling.
• It's not a very fast script, mostly because every character in the text file becomes a separate frame of the animation, but being only a few colors, very nearly black and white, the result is a pretty small file size.
• I don't have a way to run IM7 on a *nix system, so I can't translate and test it. Windows has some pretty goofy ways to handle variables in a loop, so making it *nix friendly won't be as easy as changing end-of-line characters and escaping parentheses the way we do with simpler IM commands. If you're running *nix, you'll have to work out those details on your own.