如何在创建后将动态生成的PHP图像显示在网页上?

时间:2013-04-29 17:52:10

标签: php gd

好的,我的问题是我想在网页生成后在网页上显示动态生成的图像,并提供用户使用图像的链接。当我试图回显图像时:

echo '<img src="link/sig.php?username='.$_GET['username'].'&fakeparm=.png />';

网页显示图片正常,但增加了一百万个奇怪的字符。以下是图片创建代码段。

$image_link = 'image.png';
$image = imagecreatefrompng($image_link);

$font_colour = imagecolorallocate($image, 0, 0, 0);
$font_size = 3; 

$x = array('28', '80', '135', '188', '240'); 
$y = array('8', '29', '52', '77', '100'); 

$i = '0';
$a = '0';
foreach($stat as $s_key => $value){
    imagestring($image, $font_size, $x[$a], $y[$i], $value[1], $font_colour);
     $i++;
if($i == '5'){
    $i = '0';
    $a++;
}
}

imagestring($image, $font_size, '230', '100', 'Total:'. $overall[1], $font_colour);
imagestring($image, $font_size, '240', '75', '' . $username, $font_colour);
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);

$stat的价值。

$stats = explode("\n", $website);
$overall = explode(",", $stats[0]);
$stat['att'] = explode(",", $stats[1]);
$stat['def'] = explode(",", $stats[2]);
$stat['str'] = explode(",", $stats[3]);
$stat['hp'] = explode(",", $stats[4]);
$stat['rng'] = explode(",", $stats[5]);
$stat['pry'] = explode(",", $stats[6]);
$stat['mag'] = explode(",", $stats[7]);
$stat['ck'] = explode(",", $stats[8]);
$stat['wc'] = explode(",", $stats[9]);
$stat['flt'] = explode(",", $stats[10]);
$stat['fsh'] = explode(",", $stats[11]);
$stat['fm'] = explode(",", $stats[12]);
$stat['cra'] = explode(",", $stats[13]);
$stat['smi'] = explode(",", $stats[14]);
$stat['min'] = explode(",", $stats[15]);
$stat['her'] = explode(",", $stats[16]);
$stat['ag'] = explode(",", $stats[17]);
$stat['th'] = explode(",", $stats[18]);
$stat['sl'] = explode(",", $stats[19]);
$stat['frm'] = explode(",", $stats[20]);
$stat['rc'] = explode(",", $stats[21]);
$stat['hun'] = explode(",", $stats[22]);
$stat['cs'] = explode(",", $stats[23]);

注意:图片生成正常,一切正常......我想在网页上显示生成的图片,而不是转发到图片本身......

2 个答案:

答案 0 :(得分:1)

您尚未关闭img标记...

 echo '<img src="link/sig.php?username='.$_GET['username'].'&fakeparm=.png" />';

而不是

 echo '<img src="link/sig.php?username='.$_GET['username'].'&fakeparm=.png />';

答案 1 :(得分:0)

在声明标题之前,请确保没有字符或浏览器输出。甚至没有空格。 否则,浏览器可能会尝试将图像读取为html,为您提供“百万奇怪的字符”。