我試圖在圖像中寫文本只是爲了測試目的,因爲我的Zabbix安裝不是在圖形中寫文本。我已將php.net網站的代碼複製下來(http://php.net/manual/en/function.imagettftext.php)imagettftext不能正常工作
<?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);
?>
有沒有人有想法?
描述問題。什麼不起作用? – Phil
我弄清楚這裏有什麼問題。訪問truetype文件的權限。 PHP無法訪問該文件,因此無法寫入。 我沒有看到問題,因爲我沒有使用E_ALL運行。現在一切順利運行 – gawry