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

Dear Perlmonks,

Please help me get back from around the bend... where I've been driven by incessant GD::Graph / Graph::Text font errors, specifically:

Text.pm:94: Can't locate auto/GD/gdSmallFont.al in @INC, and,

Text.pm:94: Use of inherited AUTOLOAD for non-method GD::gdSmallFont() is deprecated

I've tried to avoid the issue of "built-in" fonts by setting fonts directly, to no avail. Here's the code:

use GD; use GD::Graph::lines; my $graph = GD::Graph::lines->new(400, 300); $graph->set_x_label_font('arial',12); $graph->set_y_label_font('arial',12); $graph->set_x_axis_font('arial',12); $graph->set_y_axis_font('arial',12); $graph->set_values_font('arial',12); $graph->set_title_font('arial',12); $graph->set_legend_font('arial',12); 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) ] ); $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 $graph->error; my $gd = $graph->plot(\@data) or die $graph->error;

Have the monks any perl wisdom on this vexing issue?

Specifically,

  1. How can I get GD::Graph to work, and,
  2. How can I avoid the AUTOLOAD deprecation issue?

TIA.

  • Comment on GD::Graph Problems: Missing "built-in" font & AUTOLOAD deprecation
  • Download Code

Replies are listed 'Best First'.
Re: GD::Graph Problems: Missing "built-in" font & AUTOLOAD deprecation
by zentara (Cardinal) on Jul 25, 2012 at 09:39 UTC
    Your code runs without error for me, I'm guessing that your gd c-lib was built without TrueType Font support. You could try installing the latest GD c -lib from GD c-lib , building it with TTF support, then rebuild the Perl module. See GD with TTF support, it says you need the FreeType 2.x library.

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

      I'm thinking it's NOT GD. Here's why:

      I was able to generate a sample graph using GD and php with the following code:

      header("Content-type: image/png"); $arrval = array(12,123,21,32,77,85,166,176,163,121); $height = 260; $width = 330; $im = imagecreate($width,$height); $white = imagecolorallocate($im,255,255,255); $gray = imagecolorallocate($im,200,200,200); $black = imagecolorallocate($im,0,0,0); $red = imagecolorallocate($im,255,0,0); $x = 21; $y = 11; $num = 0; while($x<=$width && $y<=$height){ $prcnt = ((($height-50)-($y-1))/($height-60))*100; imageline($im, 21, $y, $width-10, $y, $gray); imageline($im, $x, 11, $x, $height-50, $gray); imagestring($im,2,1,$y-10,$prcnt.'%',$red); imagestring($im,2,$x-3,$height-40,$num,$red); $x += 30; $y += 20; $num++; } $tx = 20; $ty = 210; foreach($arrval as $values){ $cx = $tx + 30; $cy = 200-$values; imageline($im,$tx,$ty,$cx,$cy,$red); imagestring($im,5,$cx-3,$cy-13,'.',$red); $ty = $cy; $tx = $cx; } imageline($im, 20, 11, 20, $height-50, $black); imageline($im, 20, $height-49, $width-10, $height-49, $black); imagestring($im,3,10,$height-20,'Line Graph by: Roseindia Technologies +',$red); imagepng($im);

      So that tells me GD is installed properly and working.

      I'm still getting the same "font not found" error, so it's down to a perl problem.

      You're the perl monks, right? Any wisdom?

Re: GD::Graph Problems: Missing "built-in" font & AUTOLOAD deprecation
by Khen1950fx (Canon) on Jul 25, 2012 at 10:34 UTC
    Your script didn't work for me, so I rearranged it. You had forgotten to include a few details. Give this a try:
    #!/usr/bin/perl use strict; use warnings; use GD; use GD::Text; use GD::Graph::lines; my $graph = GD::Graph::lines->new(); $graph->set_x_label_font('/fonts/arial.ttf', 12); $graph->set_y_label_font('/fonts/arial.ttf', 12); $graph->set_x_axis_font( '/fonts/arial.ttf', 12); $graph->set_y_axis_font( '/fonts/arial.ttf', 12); $graph->set_values_font( '/fonts/arial.ttf', 12); $graph->set_title_font ( '/fonts/arial.ttf', 12); $graph->set_legend_font( '/fonts/arial.ttf', 12); 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) ] ); $graph->set( x_label => 'X Label', y_label => 'Y label', title => 'Some simple graph', y_max_value => 8, y_min_value => -6, y_tick_number => 14, y_label_skip => 2, box_axis => 0, line_width => 3, transparent => 0, ) or die $graph->error; my $gd = $graph->plot(\@data) or die $graph->error; open(IMG, '>file.png') or die $!; binmode IMG; print IMG $gd->png;
      If the "missing details" were the "use strict" and "warn" directives, I excluded them as irrelevant to the code sample. If there was some other element, could you be more specific?
Re: GD::Graph Problems: Missing "built-in" font & AUTOLOAD deprecation
by kurta (Novice) on Jul 26, 2012 at 00:00 UTC

    I reinstalled gd2 via MacPorts and reinstalled GD.pm. I'm still getting the same errors.

    MacPorts has supposedly resolved an issue with failure to find the fonts directory, but this seems to be a problem with GD::Graph::Lines itself (or rather, GD::Text since the error actually references that module):

    Text.pm:94: Can't locate auto/GD/gdSmallFont.al in @INC

    This appears to be an automatic requirement for a font that's not even used!

      Hi, see Font question regarding GD.pm

      Your PhP script had no use of True Type Fonts, so just because it ran, dosn't mean your GD libs are up to doing TrueType.

      Your problem is just setting up your True Type fonts correctly.

      It is a well known problem that GD requires full path names to the ttf file. Just specifying 'arial' won't do. Also read "perldoc GD" and look for the section "Character and String Drawing", wherein it says

      $font = GD::Font->load($fontfilepath) This method dynamically loads a font file, returning a font + that you can use in subsequent calls to drawing methods. For example: my $courier = GD::Font->load('./courierR12.fnt') or die +"Can't load font"; $image->string($courier,2,10,"Peachy Keen",$peach);
      Even in the docs, the ./courierR12.fnt file is in the scripts working directory. Try copying your arial font file to the CWD of the script. There is also mention of using stringFT for TrueType fonts, google for examples if you need them.

      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku ................... flash japh