1. 程式人生 > >php代碼畫足球場

php代碼畫足球場

填充 clas .cn head pixel arc create str ade

用代碼畫了個足球場

原圖:
技術分享

代碼畫出的效果圖:

技術分享

代碼如下:

// 創建一個 200X200 的圖像
$img = imagecreate(800, 500);

// 分配顏色
$bg = imagecolorallocate($img, 0, 120, 0);
$white = imagecolorallocate($img, 255, 255, 255);
$black = imagecolorallocate($img, 0, 0, 0);

// 填充背景色
imagefill($img, 800, 500, $bg);

// 畫線
// 四邊
imageline($img, 25, 25, 775, 25, $white
); imageline($img, 25, 475, 775, 475, $white); imageline($img, 25, 25, 25, 475, $white); imageline($img, 775, 25, 775, 475, $white); // 中分線 imageline($img, 400, 25, 400, 475, $white); // 中分點 imagesetpixel($img, 400, 250, $white); imagesetpixel($img, 399, 250, $white); imagesetpixel($img, 401, 250, $white); imagearc(
$img, 400, 250, 4, 4, 0, 360, $white); // 中分圓 imagearc($img, 400, 255, 150, 150, 0, 360, $white); // 左球門 imageline($img, 25, 175, 65, 175, $white); imageline($img, 25, 325, 65, 325, $white); imageline($img, 65, 175, 65, 325, $white); imageline($img, 25, 105, 155, 105, $white); imageline($img, 25, 395, 155, 395, $white
); imageline($img, 155, 105, 155, 395, $white); imagesetpixel($img, 120, 250, $white); imagearc($img, 120, 250, 4, 4, 0, 360, $white); imagearc($img, 155, 250, 50, 125, 270, 450, $white); // 右球門 imageline($img, 735, 175, 775, 175, $white); imageline($img, 735, 325, 775, 325, $white); imageline($img, 735, 175, 735, 325, $white); imageline($img, 775, 105, 650, 105, $white); imageline($img, 775, 395, 650, 395, $white); imageline($img, 650, 105, 650, 395, $white); imagesetpixel($img, 680, 250, $white); imagearc($img, 680, 250, 4, 4, 0, 360, $white); imagearc($img, 650, 250, 50, 125, 90, 270, $white); // 兩邊小長方形 imageline($img, 25, 225, 20, 225, $white); imageline($img, 25, 275, 20, 275, $white); imageline($img, 20, 225, 20, 275, $white); imageline($img, 775, 225, 780, 225, $white); imageline($img, 775, 275, 780, 275, $white); imageline($img, 780, 225, 780, 275, $white); // 四個角 imagearc($img, 25, 25, 23, 23, 0, 90, $white); imagearc($img, 775, 25, 23, 23, 90, 180, $white); imagearc($img, 25, 475, 23, 23, 270, 360, $white); imagearc($img, 775, 475, 23, 23, 180, 270, $white); // 將圖像輸出到瀏覽器 header("Content-type: image/png"); imagepng($img); // 釋放內存 imagedestroy($img);

php代碼畫足球場