imagefilledarc() เป็นฟังก์ชัน inbuilt ใน PHP ที่ใช้ในการวาดส่วนโค้งบางส่วนและเติมเต็ม
ไวยากรณ์
bool imagefilledarc($image, $cx, $cy, $width, $height, $start, $end, $color, $style)
พารามิเตอร์
imagefilledarc() ใช้พารามิเตอร์เก้าตัว:$image, $cx, $cy, $width, $height, $start, $end, $color และ $style
-
$image − ส่งคืนโดยฟังก์ชันการสร้างภาพ imagecreatetruecolor() ฟังก์ชันนี้ใช้สร้างขนาดของภาพ
-
$cx − ตั้งค่าพิกัด x ของจุดศูนย์กลาง
-
$cy − ตั้งค่าพิกัด y ของจุดศูนย์กลาง
-
$ความกว้าง − กำหนดความกว้างของส่วนโค้ง
-
$ความสูง − ตั้งค่าความสูงของส่วนโค้ง
-
$start − มุมเริ่มต้นเป็นองศา
-
$end − มุมปลายโค้ง หน่วยเป็นองศา 00 อยู่ที่ตำแหน่งสามนาฬิกา และส่วนโค้งจะถูกวาดตามเข็มนาฬิกา
-
$สี − มันคือตัวระบุสีที่สร้างด้วยฟังก์ชัน imagecolorallocate()
-
$สไตล์ − แนะนำวิธีเติมรูปภาพและค่าของรูปภาพเป็นใครก็ได้จากรายการต่อไปนี้ -
-
IMG_ARC_PIE
-
IMG_ARC_CHRD
-
IMG_ARC_NOFILL
-
IMG_ARC_EDGED
-
ทั้ง IMG_ARC_PIE และ IMG_ARC_CHRD เป็นคนละเรื่องกัน
IMG_ARC_CHRD เชื่อมเป็นเส้นตรงจากมุมเริ่มต้นและจุดสิ้นสุด ขณะที่ IMG_ARC_PIE ทำให้ได้ขอบมน
IMG_ARC_NOFILL บ่งชี้ว่าส่วนโค้งหรือคอร์ดควรมีโครงร่างไม่เต็ม
IMG_ARC_EDGED ใช้ร่วมกับ IMG_ARC_NOFILL แสดงว่ามุมเริ่มต้นและจุดสิ้นสุดควรเชื่อมต่อกับจุดศูนย์กลาง
คืนค่า
คืนค่า True เมื่อสำเร็จและ False เมื่อล้มเหลว
ตัวอย่างที่ 1
<?php
define("WIDTH", 700);
define("HEIGHT", 550);
// Create the image.
$image = imagecreate(WIDTH, HEIGHT);
// Allocate colors.
$bg = $white = imagecolorallocate($image, 0x00, 0x00, 0x80);
$gray = imagecolorallocate($image, 122, 122, 122);
// make pie arc.
$center_x = (int)WIDTH/2;
$center_y = (int)HEIGHT/2;
imagerectangle($image, 0, 0, WIDTH-2, HEIGHT-2, $gray);
imagefilledarc($image, $center_x, $center_y, WIDTH/2,
HEIGHT/2, 0, 220, $gray, IMG_ARC_PIE);
// Flush image.
header("Content-Type: image/gif");
imagepng($image);
?> ผลลัพธ์

ตัวอย่างที่ 2
<?php
// Created the image using imagecreatetruecolor function.
$image = imagecreatetruecolor(700, 300);
// Allocated the darkgray and darkred colors
$darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90);
$darkred = imagecolorallocate($image, 0x90, 0x00, 0x00);
// Make the 3D effect
for ($i = 60; $i > 50; $i--) {
imagefilledarc($image, 100, $i, 200, 100, 75, 360, $darkred, IMG_ARC_PIE);
}
imagefilledarc($image, 100, $i, 200, 100, 45, 75 , $darkgray, IMG_ARC_PIE);
// flush image
header('Content-type: image/gif');
imagepng($image);
imagedestroy($image);
?> ผลลัพธ์
