imageopenpolygon() เป็นฟังก์ชัน inbuilt ใน PHP ที่ใช้ในการวาดรูปหลายเหลี่ยมแบบเปิดบนรูปภาพที่กำหนด
ไวยากรณ์
bool imageopenpolygon(resource $image,array $points,int $num_points,int $color)
พารามิเตอร์
imageopenpolygon() ใช้พารามิเตอร์ที่แตกต่างกันสี่ตัว:$image, $points, $num_points and$color.
-
$image − ระบุทรัพยากรรูปภาพที่จะใช้งาน
-
$image − ระบุทรัพยากรรูปภาพที่จะใช้งาน
-
$points − ระบุจุดของรูปหลายเหลี่ยม
-
$num_points − ระบุจำนวนจุด จำนวน (จุดยอด) ทั้งหมดต้องมีอย่างน้อยสามจุด
-
$สี − พารามิเตอร์นี้ระบุสีของรูปหลายเหลี่ยม
คืนค่า
imageopenpolygon() คืนค่า True เมื่อสำเร็จและ False เมื่อล้มเหลว
ตัวอย่างที่ 1
<?php
// Create a blank image using imagecreatetruecolor() function.
$img = imagecreatetruecolor(700, 300);
// Allocate a color for the polygon
$col_poly = imagecolorallocate($img, 0, 255, 0);
// Draw the polygon
imageopenpolygon($img, array(
0, 0,
100, 200,
400, 200
),
3,
$col_poly);
// Output the picture to the browser
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?> ผลลัพธ์

ตัวอย่างที่ 2
<?php
// Create a blank image using imagecreatetruecolor() function.
$image = imagecreatetruecolor(700, 300);
// allocate the colors
$blue = imagecolorallocate($image, 0, 255, 255);
// Six points of the array
$points = array(
60, 130,
130, 230,
280, 230,
350, 130,
210, 30,
60, 130
);
// Create a polygon
imageopenpolygon($image, $points, 6, $blue);
// Output to the browser
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?> ผลลัพธ์
