trueColor() bug in GD::Graph

Hacking on a new rule-QA subsystem for SpamAssassin, I came across this bug in GD::Graph. If:

  • you are drawing a graph using GD::Graph;
  • outputting in PNG or GIF format;
  • and the ‘box’ area — the margins outside the graph — keeps coming up as black, instead of white as you’ve specified;

check your code for calls to GD::Image->trueColor(1);, or the third argument to the GD::Image->new() constructor being 1. It appears that there’s a bug in the current version of GD (or GD::Graph) where graphing to a true-colour buffer is concerned, in that the ‘box’ area continually comes out in black.

(Seen in versions: perl 5.8.7, GD 2.23, GD::Graph 1.43 on Linux ix86; perl 5.8.6, GD 2.28, GD::Graph 1.43 on Solaris 5.10.)

This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink. Both comments and trackbacks are currently closed.


  1. Posted October 28, 2005 at 21:11 | Permalink
  2. Posted October 29, 2005 at 11:39 | Permalink

    It is certainly due to a non filled background, with palette images, the first color allocated will be the bgd color (ie white). With truecolor images, it is alway black (0x0) and you have to fill the image.


  3. Posted October 29, 2005 at 20:29 | Permalink

    hi Pierre —

    I thought it may be that, too. It’s still a bug in GD::Graph in that case, anyway, since it occurs even if ‘boxclr’ is set to white.

    Also, if you’re using GD::Graph, you cannot fill the image before GD::Graph draws the graph into it with $gd->plot() anyway, as far as I know?

  4. Pierre
    Posted October 30, 2005 at 09:27 | Permalink

    does $graph->gd() still exist?

    It returns the GD::Image object that is going to be used to draw on. You can call it before or after plot(), if it called before, you are responsible for both bgd and transparent colors.

  5. Posted October 30, 2005 at 21:48 | Permalink

    Yep, it does (and it’s good to know that’s doable). However, that’s still just a workaround rather than a bug fix ;)

  6. Ben Warfield
    Posted February 16, 2006 at 07:59 | Permalink

    The easy fix (which will appear in the next version, hopefully this weekend) is to just make it always produce a palette-based image, ignoring the global setting for GD. This presumes that 256 colors ought to be enough for anybody, which sounds intrinsically hazardous but probably won’t bite me in the too immediate future.

    After the bug backlog is cleared, though, I could patch it up so that true-color graphs were a realistic option–does that sound like an option with real-world uses, or would it be a waste of time?

  7. me
    Posted March 2, 2007 at 07:38 | Permalink

    fouund this log while looking for help online re GD::GRAPH

    per the documentation there’s a known bug: “GD::Graph objects cannot be reused. To create a new plot, you have to create a new GD::Graph object.”

    How does one go about creating multiple charts?