【发布时间】:2011-08-11 23:33:58
【问题描述】:
我尝试在图像中写入文本只是为了测试目的,因为我的 Zabbix 安装没有在图表中写入文本。我从 php.net 网站 (http://php.net/manual/en/function.imagettftext.php) 复制了下面的代码
<?php
// Set the content-type
header('Content-Type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
有人有想法吗?
【问题讨论】:
-
描述您的问题。什么不工作?
-
我已经弄清楚这里出了什么问题。访问 truetype 文件的权限。 PHP 无法访问该文件,因此无法写入。我没有看到问题,因为我没有使用 E_ALL 运行。现在一切顺利