imagettftext不工作 [英] imagettftext not working

查看:169
本文介绍了imagettftext不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在图像中写文本仅用于测试,因为我的Zabbix安装不是在图形中写入文本。我从php.net网站复制了下面的代码( http://php.net /manual/en/function.imagettftext.php

I've tried to write text in an image just for testing purposes because my Zabbix install is not writing text in the graphs. I've copied the code bellow from the php.net website (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无法访问该文件,因此无法写入。

I've figure out what was the problem here. Permissions to access the truetype file. PHP could not access the file so it couldn't write.

我没有看到问题,因为我没有运行E_ALL。现在一切顺利运行

I was not seeing the problem because I was not running with E_ALL. Now everything is running smoothly

这篇关于imagettftext不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆