Originally published on: Tue, 25 Aug 2009 00:52:55 +0000
Some time ago, I tried to use PerlMagick to create a scrolling text banner as an animated GIF. The three sample programs below illustrate the approaches I took.
All of the Perl code samples are licensed under the MIT/X11 license below. I've placed it in a single spot because the sample source code files are so small
The first thing I needed to accomplish was to place text on an image and write it out as a GIF.
scroll1.pl
The code above generates the simple, non-animated GIF file scroll1.gif

( Note that after you've toyed with these scripts, you might want to change the image dimensions from "150x15" as well as changing the pointsize from 13 to something larger. If you do, please adjust the y coordinate so that you can see your text in an example like scroll1.pl before you make the counterpart changes to scroll2.pl and scroll3.pl. )
The file 'comic.ttf' needs to be accessible by the Perl script. I copied this file from my c:\windows\fonts\ folder to the same folder where I was keeping my Perl scripts.
After reading an example on the web, I thought that I could animate the GIF by using a variable for the "x" location in the Annotate() function. My attempt is captured in the code below:
scroll2.pl
This creates the file scroll2.gif which can be seen below:

What a mess! The background does not seem to clear as I overwrote each frame.
While I would assume that a better way to do this exists, I chose to write each frame out as a separate file, then reload each one of those files into an aggregated image called $maingif. After I call Read() to load each temporary GIF, I use unlink to remove the GIF. At the end of the loop, I write out the animated GIF.
scroll3.pl
The resulting file, scroll3.gif can be seen below:

Unless otherwise noted, all code and text entries are Copyright ©2009 by James K. Lawless
Save to del.icio.us
Save to StumbleUpon
Digg it
Save to Reddit
Share on Facebook
Share on Twitter
More bookmarks
| Previous post: | Tracing XSLT with a Tiny Java Web Server |
|---|---|
| Next post: | A Simple Media Control Interface Script Processor |
Subscribe!
Auto Save Clipboard Images Redux
Extending SpiderMonkey JavaScript on Windows
Rhino JavaScript to EXE with launch4j
Compiling Rhino JavaScript to Java
Directory Traversal in Rhino JavaScript
A Command-Line MP3 Player for Windows
Auto Save Images from the Clipboard
Java in a Windows EXE with launch4j
An Interview with Tom Zimmer: Forth System Developer
Setting Windows Console Text Colors in C
A Simple Parser for a Small Command Line Interface
Internet Protocols and Rhino JavaScript
Extending SpiderMonkey JavaScript on Windows
Extracting URL Addresses from Text in C
Auto Save Images from the Clipboard
Screen Capture from Multiple Monitors in Java
Stacking Images with PerlMagick
MicroISV on a Shoestring
DadHacker
The Bottom Feeder
Writin' That Code!
The Recursive ISV
The Thomsen Blog
Prototypically Speaking
The Reinvigorated Programmer