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

We are attempting to automate several of our report processes, one of which includes some standard graphing of data. As such we are evaluating some different ways to accomplish this. The are a couple of ways were are looking at, one is the GD Module. I didn't see anything in the documentation about resolution. We need the resulting graphs to be print quality (300 DPI), does GD allow for this?

It appears as though you can save the graphs to a file for later retrieval, which seems handy. Has anyone been successful at this?

Does anyone have a sample of graph that they generated from GD they'd be willing to share for further review?

FYI - other methods being looked at, dumping out XML data from the database and feeding to a mac graphing program, and a JAVA API.

Replies are listed 'Best First'.
Re: gd module ouput examples
by flounder99 (Friar) on Jul 14, 2003 at 20:16 UTC
    Install GD::Graph and run this example:
    use strict; use GD::Graph::lines; #use GD::Graph; my @data = ( ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"], [ 1, 2, 5, 6, 3, 1.5, 1, 3, 4], [ sort { $a <=> $b } (1, 2, 5, 6, 3, 1.5, 1, 3, 4) ] ); my $my_graph = GD::Graph::lines->new(400, 300); $my_graph->set( x_label => 'X Label', y_label => 'Y label', title => 'Some simple graph', y_max_value => 8, y_tick_number => 8, y_label_skip => 2 ) or die $my_graph->error; my $gd = $my_graph->plot(\@data) or die $my_graph->error; open(IMG, '>file.png') or die $!; binmode IMG; print IMG $gd->png; close IMG;
    Then just take a look at file.png. I took this example from the GD::Graph man page. This is a line graph, just s/GD::Graph::lines/GD::Graph::bars/ for a bar graph.

    --

    flounder

Re: gd module ouput examples
by tilly (Archbishop) on Jul 14, 2003 at 19:21 UTC
    For an overview of what you can do with GD I would suggest installing GD::Graph and then running its example scripts and examining the output.

    I have no idea whether you can get acceptable resolution with it, or if its features are sufficient to your needs, but that should be enough for you to evaluate it.

    Also I suggest adding Image::Magick to the list of alternatives that you are examining. It uses a different underlying graphics library with different capabilities. (Another candidate is the Gimp, but not having had occasion to use either I can't seak to their capabilities.)

Re: gd module ouput examples
by Taulmarill (Deacon) on Jul 14, 2003 at 19:36 UTC
Re: gd module ouput examples
by halley (Prior) on Jul 14, 2003 at 20:19 UTC
    A common misconception about DPI: there's nothing about digital bitmap file formats that directly define the print resolution or quality. To raise the resolution of images, you must (1) allocate a larger number of pixels, and (2) tell the applications to apply the pixels to a specific physical print/display area of your choosing.

    For example, a 64x64 pixel icon printed at 1"x1" will obviously look poor compared to a 1200x1200 pixel photographic image printed at the same 1"x1" final area.

    Some image formats may offer hints to the applications about intended print area (aka DPI fields). Some applications even allow you to adjust those fields with some GUI controls. It's still up to the applications (and device drivers) to ignore or honor these hints and really apply logical dots to physical dimensions.

    All of this is typically moot when discussing images on the screen. The user's screen will have a certain resolution of their choice (e.g., 1600x1200 pixels), and a certain viewable area defined by their hardware budget (e.g., 19" diagonal). If the viewing application doesn't scale the images accordingly (and web pages/browsers generally don't), then a 300x300 pixel image will be huge on a cheap display and tiny on an expensive display.

    --
    [ e d @ h a l l e y . c c ]

Re: gd module ouput examples
by tomhukins (Curate) on Jul 15, 2003 at 08:36 UTC
    If you want high quality output, perhaps a vector image would be more useful than a bitmapped image? You might find SVGGraph useful for outputting graphs in SVG, which you can easily convert (at various resolutions) to an appropriate format for your needs.
Re: gd module ouput examples
by kryberg (Pilgrim) on Jul 14, 2003 at 20:42 UTC