Static images may have once been worth a thousand words, but it seems as though their value has plummeted as of late. Sure, you can animate them so they dance around, and yeah, some big, fat images have millions of colors, but even the best of them just sit on a page and look pretty.
Images generated on the fly, on the other hand, have all kinds of potential. Imagine how impressed your users would be if a new, unexpected image loaded every time they hit your page. The images could be simple, eye-candy baubles with no purpose other than sprucing up a dull page with interesting color changes. Or you could really show off your muscle:
- produce graphical representations of data, and create charts and graphs at a user's request;
- generate graphical links and buttons that fit in with your site's look, and change them on demand;
- display mathematical formulae and foreign-language text that isn't supported by standard fonts;
- automatically generate snazzy animated headlines for articles pulled from a publishing-system database;
- give users their newly generated passwords as GIFs, so the text can't be grabbed by sniffy Perl bots trying to make their own user accounts and pave the road to bot domination of the Earth;
- or whatever!
Interested in learning how it's done? There're a few different engines that can run on a server and generate images. PHP has built-in functions to handle image generation, using the GD graphics library (which can also be used with Perl, via the GD.pm module). The GIMP (GNU Image Manipulation Program) has scripting capabilities that make it well-suited to this kind of work. And Flash Generator can handle it as well.
Only a little trickery is involved. The HTML on the page has the usual IMG tag, but the file it points to is a script rather than a static image file. The script, when called, generates and returns an image according to the arguments it's fed.
Since PHP is my bag (it's cheap and easy, just like me!), that's what I'll be using in the pages that follow to give you a detailed look at how you can generate images. But since PHP isn't the only way to fly, I'll also give you a general look at what can be done with GIMP and Generator.
Ready? Steady? Let's go.
next page»