【发布时间】:2013-02-06 15:32:09
【问题描述】:
我仍然在寻找这个问题的答案已经很长时间了.. 我找到的所有解决方案都是围绕捕获字体名称,但我很确定这不是我的问题。
GD好像安装了
array(11) {
["GD Version"]=>
string(27) "bundled (**2.0.34 compatible**)"
["FreeType Support"]=>
bool(false)
["T1Lib Support"]=>
bool(false)
["GIF Read Support"]=>
bool(true)
["GIF Create Support"]=>
bool(true)
["JPEG Support"]=>
bool(true)
["PNG Support"]=>
bool(true)
["WBMP Support"]=>
bool(true)
["XPM Support"]=>
bool(true)
["XBM Support"]=>
bool(true)
["JIS-mapped Japanese Font Support"]=>
bool(false)
}
在上面你可以看到我对 GD 的支持。 我的 PHP 版本是 5.3,我在 Linux 上运行。
我尝试了几个来自不同网站的不同代码示例,但没有一个有效。 ImageString 确实为我工作,但我需要让 imagettftext 工作..
这是我现在尝试的最后一个代码-
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
// Set the content-type
header('Content-Type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 100) or die("Can't create image!");
// 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, 'arial.ttf', $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, 'arial.ttf', $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
【问题讨论】:
-
如果你在imagepng之前设置了header...,你会得到什么errormsg?
-
php 是否给您任何错误/通知?
imagettftext函数返回什么?它应该返回点数组或错误时返回 false。试试$text_result = imagettftext(...); if($text_result===false){echo("ERROR");}else print_r($text_result);。另一件事,当您填充新创建的图像时,您在高度上留下了一个像素,而在宽度上只填充了 100 的 29 个像素,这是故意的吗? -
你是怎么打印那个数组的???
-
如果确实回答了您的问题,请考虑接受答案(点击左侧的勾号)
标签: php image gd imagettftext