我正在尝试使用PHP开发热图。该文件从文本文件中获取坐标值的输入,并使用PHP代码,我们在屏幕上映射这些值。我不知道我的代码有什么问题,但它没有生成任何图像。我附上了代码。
<?php
$width = 1024;
$height = 768;
$splitted[]="";
$splitted1[]="";
$x="";
$y="";
$x_value[]="";
$y_value[]="";
$im = imagecreatetruecolor($width, $height);
$red = imagecolorallocate($im, 255, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
$blue = imagecolorallocate($im, 0, 0, 255);
$gray = imagecolorallocate($im, 0xC0, 0xC0, 0xC0);
imagefill($im, 0, 0, $black);
$file = "clickcount.txt";
$fp = fopen($file, 'r') or die("error opening file");
$file = fread($fp, filesize($file));
$splitted = explode(":", $file);
for ($i = 0; $i < count($splitted); $i++)
{
if (!is_string($splitted[$i]))
return false;
//$arr_query = NULL;
$url = parse_url($splitted[$i]);
$url = $url['query'];
parse_str($url, $vars);
$x = intval($vars['x']);
$y = intval($vars['y']);
$x_value[$i]=$x;
$y_value[$i]=$y;
//imagesetpixel($im, $x, $y, $white);
//$splitted1=explode("?",$splitted[$i]);
}
for($i = 0; $i <( count($x_value)-1); $i++)
{
echo "inside the loop";
echo $x_value[$i];
echo $y_value[$i];
imagesetpixel($im, $x_value[$i], $y_value[$i], $white);
}
header('Content-Type: image/png');
imagepng( $im );
imagedestroy($im);
?>
和文本文件中的值为:
/musicstore/empty.php?x=437&y=392:
/musicstore/empty.php?x=407&y=631:
/musicstore/empty.php?x=135&y=305:
/musicstore/empty.php?x=199&y=420:
/musicstore/empty.php?x=290&y=426:
/musicstore/empty.php?x=408&y=435:
/musicstore/empty.php?x=1099&y=398:
/musicstore/empty.php?x=1104&y=256:
/musicstore/empty.php?x=1115&y=62:
/musicstore/empty.php?x=1032&y=146:
/musicstore/empty.php?x=1022&y=262:
/musicstore/empty.php?x=757&y=246:
/musicstore/empty.php?x=752&y=365:
/musicstore/empty.php?x=750&y=417:
/musicstore/empty.php?x=752&y=485: