【发布时间】:2013-03-03 10:58:34
【问题描述】:
我正在使用 Joomla 1.5。我有创建带有文本的图像的脚本,但它对我不起作用:
<?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 = "ARIAL.TFF";
// 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);
?>
我不明白为什么这不起作用。我在谷歌找到了很多例子,我用过它,但总是一样的。
这个错误的英文意思是:Image "http://juokoera.lt/a.php" can't be shown, because It have problems (errors).
我在 google 上发现,这可能是我的主机故障,我更改了它,但同样的问题。如果可以,请帮助我。非常感谢。
更新: 我遇到了同样的错误,代码如下:
dasfasdf
dfas
<?php
header('Content-Type: image/png');
$im = imagecreatetruecolor(400, 30);
$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);
$text = 'Testing...';
$font = "ARIAL.TTF";
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
imagepng($im);
imagedestroy($im); ?>
如何在同一个 php 中使用额外的文本?
【问题讨论】:
-
我猜你没有可用的“ARIAL.TFF”。确保它确实存在。当然,在注释该行之后,您的代码会生成没有任何文本的图像。
-
另外,一个常见的错误是在代码之前有任何输出。 IE。即使是图像生成 PHP 代码之前的换行符或空格字符也会导致此错误。
-
@varnie 缺少的字体文件引用不应产生此错误,只需将图像留空,不带文本。
-
ARIAL.TFF 被放置在 .../public_html/ 文件夹中,也许我需要像
$font = "/public_html/ARIAL.TFF";那样写到 ttf 的路径?这就是我所有的 a.php 文件,里面没有更多内容。 -
我用另外 1 个代码更新了我的帖子,这些代码对我返回了相同的错误。
标签: php image text joomla imagettftext