无法显示图片,因为它在php gd中包含错误 [英] Image can not be displayed because it contains error in php gd

查看:87
本文介绍了无法显示图片,因为它在php gd中包含错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是链接我正在创建图像,但是按照我在第一个示例中进行的测试,我的GD已安装并正常工作,但是此代码中断并标记"由于包含错误而无法显示图像"

This is the Link I am following to create an image, however my GD is installed and working correctly as i tested with the very first example but this code breaks and flag "Image can not be displayed because it contains error" .

代码-

<?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().
  • 检查font_path并根据注释设置字体路径.
  • 按照& .
  • Checked white/blank spaces before php tag if any.
  • Remove all code and spaces before header() method.
  • Changed imagecreate() to imagecreatetruecolor() as in comments in the code.
  • Checked font_path and set font path as per comments as well.
  • Followed this & this.

我的PHP版本- PHP版本5.3.8

仍然无法找到问题所在:(

Still unable to locate the problem :(

错误

编辑-

1.0版

这就是我要继续保存的东西.

this is what im getting on saving.

有关图像的更多信息-

保存页面时-这是文件保存的名称- create_png.php.png

on saving the page -- this is the name of file saving -- 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文件放在该文件夹下,以使此代码起作用或设置使其起作用的路径.

Font file actually missing, we need to put our .ttf file under the folder to make this code working or set path to make it work.

推荐答案

保存出现错误的图像文件,然后在文本编辑器(如记事本或等效文本编辑器)中打开它,然后查看其中是否有PHP错误.发生错误,然后输出文本,该文件损坏了文件.这样做,您将发现错误所在.

Save the image file that errors and open it in a text editor like notepad or equivalent and see if any PHP errors are inside it. An error is occurring and outputting text then which corrupts the file. Do that and you will find what the error is.

这篇关于无法显示图片,因为它在php gd中包含错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆