页面内容不显示后,我的PHP GD绘图

问题描述:

我试图让一个PHP GD旗帜像一个插件,使用户复制和粘贴图像链接,并把他们的网站,这对我来说工作确定,这个问题是,当我加载图片,其他网页内容,如文字等不显示在浏览器中页面内容不显示后,我的PHP GD绘图

这里是我的PHP代码绘制图像

<?php 
    header("Content-type: image/png"); 
    $string = $_GET['text']. ' Click Here'; 
    $im  = imagecreatefrompng("../../images/banner.png"); 
    $orange = imagecolorallocate($im, 0, 0, 0); 
    $px  = (imagesx($im) - 1.5 * strlen($string))/2; 
    $font = 'verdana.ttf'; 
    imagestring($im,50, $px, 45, $string, $orange); 
    imagepng($im); 
    imagedestroy($im); 
     ?> 

提示:我把这个代码在在页面的顶部使页眉工作

现在其他的html代码是:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>add plugin</title> 
</head> 

<body> 
<h3>Select One or More Plugin to connect your website for your reservation</h3> 

<h4>Just A Button</h4> 
<br /> 
<p>Instructions</p> 
<p>Copy this code and paste into your website</p> 

</body> 
</html> 

有人可以提出任何解决方案来克服这个问题吗?

提示:我把这个代码在页面的顶部,使头工作

那是你的问题。您基本上完成了在文本编辑器中打开计算机上的图像文件并在文件末尾键入随机字符的等效功能。它会破坏图像,你永远不会看到这些字符,因为它们在图像数据中毫无意义。

您的PHP代码无法在一个HTTP请求中返回图像和HTML。相反,您可以拥有两个不同的PHP文件,一个用于图像,一个用于HTML。让HTML通过标准<img src="image.php" alt="" />标签包含图像PHP。

+0

感谢您的详细解释,它现在的工作, – 2012-04-16 17:15:20

如果你的PHP脚本产生一个图像,那么你应该适当地包装在IMG标签的输出。

尝试,对于一个例子来添加到您的html页面:<img id="banner" src="/path/to/your.php?text=Click%20Here"/>

,如果你使用jQuery的客户端可以动态改变图像的src属性。见这里的例子:Changing the image source using jQuery

+0

感谢它的工作:),供参考两个解决方案工作 – 2012-04-16 17:14:45