php趣味编程 - php输出国际象棋棋盘
?>
$gezi = 30;
$width = $gezi*8;
$height = $gezi*8;
header("Content-type: image/gif");
$img = imagecreate($width,$height);//创建一张图片
$bg_color = imagecolorallocate($img,210,210,210);
//格子的颜色
$black_gezi_bg = imagecolorallocate($img,0,0,0);//黑色格子
$white_gezi_bg = imagecolorallocate($img,255,255,255);//白色格子
//画一个格子并填充 这边用函数imagefilledrectangle
for($i=0;$i<8;$i++){
for($j=0;$j<8;$j++){
$x1 = $j*30;//格子的左上角的坐标
$y1 = $i*30;
$x2 = ($j+1)*30;//格子的右下角的坐标
$y2 = ($i+1)*30;
if(($i+$j)%2==0)
{
$color = $black_gezi_bg;
}else{
$color = $white_gezi_bg;
}
imagefilledrectangle($img,$x1,$y1,$x2,$y2,$color);
}
}
imagegif($img);//以gif格式输出图片
imagedestroy($img);//释放图片
?>



