【发布时间】:2012-12-26 05:22:44
【问题描述】:
这是 Link 我正在创建图像,但是我的 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 标记前的空白/空格(如果有)。
- 删除 header() 方法之前的所有代码和空格。
- 将 imagecreate() 更改为 imagecreatetruecolor(),就像代码中的 cmets 一样。
- 检查 font_path 并根据 cmets 设置字体路径。
- 已关注this & this。
我的 PHP 版本 - PHP 版本 5.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 文件放在文件夹下以使此代码工作或设置路径以使其工作。
【问题讨论】: