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);
最初の正方形では問題なく機能しますが、その後は、次のように正方形が左上隅に配置されているように見えます。
なぜこれができるのでしょうか?