tomazos has asked for the wisdom of the Perl Monks concerning the following question:

I'm looking for a perl module that will produce GIFs on the fly in response to a CGI request. (ie I want to return the output from a CGI as a GIF and not as HTML.) I would need a routines that can:

1. Create a new blank 200 x 200 image in memory.

2. Write text, draw lines and shapes on it at co-ordinates I specify.

3. print the image in GIF format to standard output.

Any ideas?

Replies are listed 'Best First'.
Re: Producing images on the fly.
by monkfish (Pilgrim) on Nov 03, 2001 at 05:43 UTC
    GD.pm should do the trick.

    From the docs:

    GD.pm is a port of Thomas Boutell's gd graphics library (see below). GD allows you to create color drawings using a large number of graphics primitives, and emit the drawings as PNG files.

    GD defines the following three classes:

    GD::Image
    An image class, which holds the image data and accepts graphic primitive method calls.

    GD::Font
    A font class, which holds static font information and used for text rendering.

    GD::Polygon
    A simple polygon object, used for storing lists of vertices prior to rendering a polygon into an image.

    -monkfish (The Fishy Monk)

Re: Producing images on the fly.
by dws (Chancellor) on Nov 03, 2001 at 05:47 UTC
    I'm looking for a perl module that will produce GIFs on the fly in response to a CGI request.

    GD.pm used to emit GIFs, but that support was removed due to (Unisys) patent licensing considerations. GD now emits PNGs.

    If you can make do with PNGs instead of GIFs, GD is probably what you're looking for. Or, you might be able to score an older version of GD that still has GIF support.

    Or, in the unlikely event that you want to paint your 200x200 image in one color, you might be able to modify On-demand single-pixel GIFs.

Re: Producing images on the fly.
by growlf (Pilgrim) on Nov 03, 2001 at 12:49 UTC
    Additionally, you may want to check on the scripts and modules available for Gimp! It can do some amazing things and does them very well. Comes in both Win and *nix flavors, has a wide array of nearly fanatic folowers that crank out really nifty add-ons for it continually. It even has 3 interfaces: API, command line, and GUI. Heck, the TOOLS it uses are mostly written in Perl.

    It requires gtk/gdk as well however. Check out Marc's page and CPAN for several good links to more info on using it in perl or perl with "it". It might be heavier than you need, but if not - why reinvent the wheel?

    NOTE: It is also just a really fun thing to screw arround with during creative breaks from coding - be wary tho, I lost 40 minutes just verifying the links for this post as i got hooked on playing with it again *chuckle*

    *G*