我有以下代码,使用GD在图像上绘制绿色方块:
$img = imagecreatefrompng("images/dota.png");
$radiantcolor = imagecolorallocate($img, 7, 251, 15);
$direcolor = imagecolorallocate($img, 250, 2, 0);
$x = array(
0 => 38,
1 => 45,
2 => 25,
3 => 29,
4 => 34,
5 => 62,
6 => 83,
7 => 116,
8 => 76,
9 => 135,
10 => 232,
);
$y = array(
0 => 234,
1 => 240,
2 => 205,
3 => 161,
4 => 116,
5 => 219,
6 => 198,
7 => 171,
8 => 256,
9 => 260,
10 => 257,
);
foreach ($towerstatus_radiant as $key => $tower){
if ($tower == 1){
$x = $x[$key];
$y = $y[$key];
imagefilledrectangle($img, $x, $y, $x+8, $y+8, $radiantcolor);
}
}
header('Content-Type: image/png');
imagepng($img);
它与第一个正方形一样好用,但在那之后,正方形似乎放在左上角,就像这样:
为什么会这样?
答案 0 :(得分:2)
你在这里覆盖你的$ x和$ y变量:
$x = $x[$key];
$y = $y[$key];
您需要在此处使用不同的变量名称。