这是我创建映像所遵循的链接,但是我的GD在使用第一个示例进行测试时安装和工作正常,但是这个代码中断并标记为“图像无法显示,因为它包含错误”。
代码-
<?php
//phpinfo();
//Report any errors
ini_set("display_errors", "1");
error_reporting(E_ALL);
//Set the content type
header('content-type: image/png');
//Create our basic image stream 300x300 pixels
$image = imagecreate(300, 300);
//$image = imagecreatetruecolor(300, 300);
//Set up some colors, use a dark gray as the background color
$dark_grey = imagecolorallocate($image, 102, 102, 102);
$white = imagecolorallocate($image, 255, 255, 255);
//Set the path to our true type font
//$font_path = 'advent_light';
//$font_path = 'advent_light.ttf';
//$font_path = 'arial';
$font_path = 'arial.ttf';
//Set our text string
$string = 'Swapnesh!';
//Write our text to the existing image.
imagettftext($image, 50, 0, 10, 160, $white, $font_path, $string);
//Create our final image
imagepng($image);
//Clear up memory
imagedestroy($image);
?>
我尝试并搜索过但没有解决方案的内容如下- :(
我的PHP版本-PHPVersion5.3.8
仍然找不到问题:
误差
编辑-
1.0版
这就是我开始存钱的原因。
更多关于图像的信息--
保存页面时--这是保存文件的名称-- create_png.php.png
1.1版
<br />
<b>Warning</b>: imagettftext() [<a href='function.imagettftext'>function.imagettftext</a>]: Invalid font filename in <b>C:\xampp\htdocs\Core\CoreFiles\create_png.php</b> on line <b>20</b><br />
<br />
<b>Warning</b>: imagettftext() [<a href='function.imagettftext'>function.imagettftext</a>]: Invalid font filename in <b>C:\xampp\htdocs\Core\CoreFiles\create_png.php</b> on line <b>23</b><br />
感谢@cryptic
和@user1711126
溶液 --
字体文件实际上缺少,我们需要将我们的.ttf文件放在文件夹下,以使此代码工作或设置路径使其工作。
发布于 2012-12-26 05:27:10
保存错误的图像文件,并在文本编辑器(如记事本或等效文件)中打开该文件,查看其中是否存在PHP错误。一个错误正在发生,然后输出文本,这会破坏文件。这样做,你就会发现错误是什么。
发布于 2012-12-26 05:53:02
我严重怀疑你的字体路径,请在同一个目录下检查你的字体和文件,如果是的话,就像这样改变路径,
$font_path = './arial.ttf';
编辑(根据聊天中的讨论)
您必须需要一个ttf文件才能使用imagettftext()函数,将arial.ttf文件放在文件所在的文件夹中
发布于 2012-12-26 06:00:26
我认为@隐秘是对的,你需要使用真正的字体路径,比如
$font_path = basename(dirname(__FILE__)).'/arial.ttf';
并请确保字体存在于目录中。
https://stackoverflow.com/questions/14036298
复制相似问题