我想要做的是從csv文件加載一些值,並使用它們作爲x,y值來繪製一些矩形。基於csv數據的php繪圖
我正在加載文件,但不是顯示圖像,而是輸出原始圖像數據。我知道,在HTML代碼中,我可以使用
<img scr="foo.php"></script>
正確顯示圖像,但我不知道怎麼用這個來繪製基於關閉數據的每一行的csv文件的多個矩形。請幫忙。
CSV代碼
20,40,60,80
50,100,150,175
索引PHP代碼
<html>
<body>
<?php
include("parse.php");
?>
</body>
</html>
解析PHP代碼
<?php
include("draw.php");
$file = fopen("data.csv", "r");
while (!feof($file)) {
$line = fgetcsv($file);
drawGraph($line[0], $line[1], $line[2], $line[3]);
}
fclose($file);
?>
拉伸PHP代碼
<?php
function drawGraph($xPos, $yPos, $xxPos, $yyPos) {
//create a 200 x 200 canvas image
$canvas = imagecreatetruecolor(200, 200);
//set canvas background to white
$white = imagecolorallocate($canvas, 255, 255, 255);
imagefill($canvas, 0, 0, $white);
//create colors
$pink = imagecolorallocate($canvas, 255, 105, 180);
//draw rectangles
imagerectangle($canvas, $xPos, $yPos, $xxPos, $yyPos, $pink);
//ERROR - following line displays raw data of image not the actural image
imagepng($canvas);
imagedestroy($canvas);
}
?>
我實際上並沒有完全理解你,但也許這有助於:記住在推送原始數據之前做header('Content-Type:image/png')。 – 2012-08-12 00:56:41
你可以發佈產生的HTML嗎? – SomeKittens 2012-08-12 00:58:33
這是一些無頭‰PNGIHDRÈÈ「HTML輸出的:9E =IDATxœíÜÁ\t A0A;¤»t',Ò‰ëSÈÃA^ FAE /噸ýnclpμÇê¸'a '\t一個' \t一個 '\t一個' \t一個'\t一個' \t一個 '\t一個' \t一個 '\t一個' \t一個 '\t一個' \t一個 '\t一個' \t一個 '\t一個' \t一個 '\t一個' \t一個'‰COE÷qÑÿû¼-]Í \t sam
user1334130
2012-08-12 01:26:48