我有以下代碼,它在我的PHP文件中工作得很好,並生成一個直方圖圖像。然而,只要我添加一個html標籤,它不會再生成直方圖,而是一個空的圖像。在我看來,問題出現在第一行header("Content-type: image/jpeg");
。但我該如何解決它?圖像內容類型輸出HTML標記導致問題
<html>
<?php
// Send the PNG header information. Replace for JPEG or GIF or whatever
header("Content-type: image/jpeg");
// This array of values is just here for the example.
$data = array('3400','2570','245','473','1000','3456','780');
// Get the total value of columns we are going to plot
$sum = array_sum($data);
// Get the height and width of the final image
$height = 255;
$width = 320;
$im = imagecreate($width,$height); // width , height px
// Generate the image variables
$white = imagecolorallocate($im,255,255,255);
$black = imagecolorallocate($im,0,0,0);
$red = imagecolorallocate($im,255,0,0);
imageline($im, 10, 5, 10, 230, $black);
imageline($im, 10, 230, 300, 230, $black);
// Now plot each column
$x = 15;
$y = 230;
$x_width = 20;
$y_ht = 0;
for ($i=0;$i<7;$i++){
$y_ht = ($data[$i]/$sum)* $height;
// This part is just for 3D effect
imagerectangle($im,$x,$y,$x+$x_width,($y-$y_ht),$red);
imagestring($im,2,$x-1,$y+10,$data[$i],$black);
$x += ($x_width+20);
}
imagejpeg($im);
?>
</html>
你的日誌說......? –
可能重複的[圖形顯示不正確](http://stackoverflow.com/questions/7129173/graph-not-showing-properly) – mario