php 字符显示不出来,imagettftext不会工作;文字不显示

我正在尝试使用imagettftext()通过PHP向图像添加文本。到目前为止,我已经浏览了大约6个不同的教程,试图让它起作用,而且我没有成功。我目前正在从PHP文档页面尝试此代码。imagettftext不会工作;文字不显示

// 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 = 'arial.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);

?>

然而,没有出现。我安装了GD库,并启用了freetype。我有arial.ttf在与php文件相同的目录中,我无法弄清楚为什么它不会工作。我得到的只是一张空白图片。编辑:这是错误信息“[19-Jan-2014 16:31:07] PHP警告:imagettftext():找不到/打开/var/www/php/bb/test.php中的字体在线21“

2014-01-19

C A Mc

+0

请登录错误的文件,并张贴在这里,'的ini_set( “log_errors”,1); ini_set(“error_log”,“php-error.log”);'不要忘记在你的脚本的相同目录中创建文件'php-error.log',并为其写入权限。 –

+0

我得到这个错误“[19-Jan-2014 16:31:07] PHP警告:imagettftext():找不到/ var/21 -Jan-2014 16:31:08]“。我确定在同一个目录中有arial.ttf,所以我不知道为什么发生这种情况 –

+0

我测试了你的确切代码和它的工作 –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值