首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >imagettftext不工作

imagettftext不工作
EN

Stack Overflow用户
提问于 2011-08-12 07:33:58
回答 3查看 6.9K关注 0票数 1

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

代码语言:javascript
复制
<?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);
?>

有谁有主意吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-08-16 10:02:06

我已经弄清楚问题出在哪里了。访问truetype文件的权限。PHP无法访问该文件,因此无法写入。

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

票数 3
EN

Stack Overflow用户

发布于 2015-01-23 23:52:32

我的问题是一个错误的补偿。图像没有显示任何内容,没有文本,源代码中没有错误,只显示了一个空白文件。路径是正确的。我原以为ttf字体有误,但结果是定位错误。

以下是帮助我看了一些文本的内容:

代码语言:javascript
复制
imagettftext($im, 20, 0, 20, 20, $fg, $font, $text);

这在右上角显示了一些文本。

完整的工作代码:

代码语言:javascript
复制
    putenv('GDFONTPATH=' . dirname(__FILE__));
    $font = 'arial'; // located next to the script
    imagettftext($im, 20, 0, 20, 20, $fg, $font, $text);
票数 2
EN

Stack Overflow用户

发布于 2011-08-12 09:22:12

它是一个GD函数,您需要安装支持gettext和ttf的php-gd。

-$

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7034698

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档