dongyi1996 2013-04-29 17:52
浏览 96

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

Okay, my problem here is I want to display the dynamically generated images on a webpage after they have been generated and provide a link for the user to use the image. When I try to echo the image:

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

The webpage displays the image fine, but with the addition of a million weird characters. Below is the image creation snippet.

$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);

Value of $stat.

$stats = explode("
", $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]);

Note: Image is generated fine, everything works... I want to display the generated image on a webpage instead of being forwarded to the image itself...

  • 写回答

2条回答 默认 最新

  • dos49618 2013-04-29 18:10
    关注

    Make sure there are no characters or browser output before you declare your headers. Not even spaces. Otherwise the browser may try and read the image as html giving you your "million weird characters".

    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计