从PHP包含文件输出PNG图像

从PHP包含文件输出PNG图像,php,image,Php,Image,我有一个名为sign.php的include文件,其中包含一些代码- header('Content-type: image/png'); ..... imagepng($image_file); ..... 我想在其中显示此图像的文件-index.php ...... <what comes here?> include('../sign.php'); ..... index.php ...... <what comes here?> include('../sig

我有一个名为sign.php的include文件,其中包含一些代码-

header('Content-type: image/png');
.....
imagepng($image_file);
.....
我想在其中显示此图像的文件-index.php

......
<what comes here?> include('../sign.php');
.....
index.php

......
<what comes here?> include('../sign.php');
.....
    .......
    <?php echo '<img src="../signature/sign.php" />'; ?>
    .......
。。。。。。。
.......
还是不行

编辑:

index.php

......
<what comes here?> include('../sign.php');
.....
    .......
    <?php echo '<img src="../signature/sign.php" />'; ?>
    .......
include('../signature/sign.php');
回声';
sign.php

    .....
   {
    imagettftext($im, 22, 0, 240, 43 , $text_color, $font, $text_god);
    imagettftext($im, 22, 0, 241, 44 , $text_color, $font, $text_god);
}
imagettftext($im, 22, 0, 60, 42 , $text_color, $fontname, $text_username);
     imagettftext($im, 16, 0, 230, 72 , $text_color, $font, $text_kills);
imagettftext($im, 16, 0, 230, 102 , $text_color, $font, $text_deaths);
imagettftext($im, 16, 0, 230, 132 , $text_color, $font, $text_rwon);

imagettftext($im, 16, 0, 365, 72 , $text_color, $font, $text_alevel);
imagettftext($im, 16, 0, 365, 102, $text_color, $font, $text_dlevel);
imagettftext($im, 16, 0, 365, 132 , $text_color, $font, $text_rlost);
imagettftext($im, 16, 0, 365, 162 , $text_color, $font, $text_money);   // Prints the money in the picture. 

imagecopymerge($im, $skinImg, 505, 56,0,0,55,99,100);

header('Content-Type: image/png');

imagepng($im); 

    imagedestroy($im); 

发生这种情况是因为
imagepng
直接将图像内容输出到浏览器。 您应该将图像的内容保存到
sign.php
中的如下变量中:

... 
imagecopymerge($im, $skinImg, 505, 56,0,0,55,99,100);  

ob_start();
imagepng($im);
$stringdata = ob_get_contents();
ob_end_clean();

imagedestroy($im);   
...
然后将其显示在index.php中,如下所示:

<?php
    include('sign.php');
    echo '<img src="data:image/png;base64,' . base64_encode($stringdata) . '">';
?>

'>

<>这对你有用。

根据你说你试过<代码> <代码>,它不起作用,我猜设置标题有什么不对,请考虑

发送头之前没有输出 在进行任何输出之前,必须调用发送/修改HTTP头的函数

修改HTTP头的一些函数包括:

  • /
  • /
  • /
输出可以是:

  • 无意的:
    • 以前的错误消息或通知
  • 有意的:
    • print
      echo
      和其他生成输出的函数(如
      var\u dump

    • 原始
      区域在
      回声“”之前;使用普通的img标记,src是通过浏览器访问php fileis sign.php的路径吗?我的意思是,如果手动输入URL,它会显示图像吗?实际上不会,因为它需要index.php中的变量!哦你的问题中没有提到。。我会编辑我的答案,几秒钟后检查出来。你能从index.php发布更多的代码吗@RajatPawar@RajatPawar你能检查一下我的新解决方案是否有效吗?我完全按照你说的做了,但现在它显示了很多胡言乱语!有点像——”�巴布亚新几内亚IHDR���G IDATx�L�ْ,Yv�����B��英国�.tChB�D%3��E�?�/���/���/4.�D��PF� ���F�P���s�>�ao=xd� ���"+ 应该是.echo“”;@RezaSh谢谢:)在几种编程语言上编写的所有这些内容可能会让人非常困惑..编辑我的回答谢谢回答-sign.php无法直接工作,因为它在index.php中使用了一个变量!