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
Views expressed in this blog are those of the author and do not necessary reflect those of the author's employer. Views expressed in the comments are those of the responding individual.

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 |
Click **here**
A JavaScript REPL for Android Devices
A Review of Kevin Mitnick's Book Ghost in the Wires
Play MP3 Files with Python on Windows
PHP, Transparent GIF's, and Web Tracking
Switching a Console Window to Full Screen or Windowed Mode
Twimmando: A Command-line Twitter Client
A Scrolling Banner using Canvas and JavaScript
Checking Shift States with DEBUG
A Review of Kevin Mitnick's Book Ghost in the Wires
Why Some Web Sites will go Dark on Jan 18th
Book Review : Paull Allen - Idea Man
A 90's Experiment in Online Systems - The U.S. West CommunityLink Service