我正在尝试一些示例代码,以便用PHP5-GD libaray进行实验。我已经为Google做出了一些努力,但没有成功。 我在文档根目录下有一个字体:/home//www/tiffanytwolight-regular.ttf(我已经将/ var/www/html /这是我安装时的默认根目录下的文档根目录)。我想绘制一个直方图。 重要的代码片段是:如何在Linux Mint 17.2下使用PHP提供字体?
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;
}
}
我还没有成功地给$字体的有意义的内容。 $ this->字体发生多次但未设置。 实例:
$box = ImageTTFbBox($textsize, 0, $this->font, $key);
ImageTTFText($image, $textsize, 0, ($center-($tw/2)),
($this->totalheight-$this->ygutter), $black,
$this->font, $key);
调用类函数是代码: 包括( “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();
这将导致一个错误的信息(通过函数ini_set '上'( '的display_errors',):
()警告:imagettfbbox():找不到/打开字体在/ home /par/www/SimpleBar.class.php线30
我希望得到一些很好的提示。
是的,这工作,非常感谢。我之前没有使用过这个库,所以我从网上找到的一些代码开始,对此进行测试。并没有显示任何图形,只是在屏幕左上角的一个小方块。 –