I am trying out some sample code in order to experiment with the PHP5-GD libaray. I have made several efforts to Google for an answer, but no success. I have a font under document root: /home//www/tiffanytwolight-regular.ttf (I have changed document root from /var/www/html/ which is the default root in my installation). I want to draw a bar histogram. Important code-snippets are:
class SimpleBar {
private $xgutter = 20; // left/right margin
private $ygutter = 20; // top/bottom margin
private $bottomspace = 30; // gap at the bottom
private $internalgap = 20; // space between bars
private $cells = array(); // labels/amounts for bar chart
private $totalwidth; // width of the image
private $totalheight; // height of the image
private $font; // the font to use
function __construct( $width, $height, $font ) {
$this->totalwidth = $width;
$this->totalheight = $height;
$this->font = $font;
}
}
I have not succeeded in giving $font a meaningful content. $this->font occurs several times but is not set. Examples:
$box = ImageTTFbBox( $textsize, 0, $this->font, $key );
ImageTTFText( $image, $textsize, 0, ($center-($tw/2)),
($this->totalheight-$this->ygutter), $black,
$this->font, $key );
The code that calls the class functions is: include("SimpleBar.class.php");
$graph = new SimpleBar( 500, 300, "tiffanytwolight-regular.ttf" );
$graph->addBar( "USA", 200 );
$graph->addBar( "India", 400 );
$graph->addBar( "UK", 240 );
$graph->addBar( "Australia", 170 );
$graph->addBar( "UAE", 270 );
$graph->draw();
This results in an error message (via ini_set('display_errors', 'on'):
(!) Warning: imagettfbbox(): Could not find/open font in /home/par/www/SimpleBar.class.php on line 30
I would appreciate some good hints.