Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

PHP – วาด Open Polygon ด้วย imageopenpolygon()

ฟังก์ชัน imageopenpolygon() ใช้วาด open polygon (ไม่ปิดท้าย) บนรูปภาพที่กำหนด

รูปแบบการใช้งาน (Syntax)

bool imageopenpolygon(GdImage $image, array $points, int $num_points, int $color)

พารามิเตอร์

  • $image – GdImage resource
  • $points – array ของพิกัด [x1, y1, x2, y2, ...]
  • $num_points – จำนวน vertices (ต้องมากกว่าหรือเท่ากับ 3)
  • $color – สีของ polygon

ค่าที่คืนกลับ

คืน true เมื่อสำเร็จ false เมื่อล้มเหลว

ตัวอย่าง 1: สามเหลี่ยมเปิด

<?php
$img = imagecreatetruecolor(700, 300);
$col_poly = imagecolorallocate($img, 0, 255, 0);
imageopenpolygon($img, [0, 0, 100, 200, 400, 200], 3, $col_poly);
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?>

ผลลัพธ์

PHP – วาด Open Polygon ด้วย imageopenpolygon()

ตัวอย่าง 2: รูปหกเหลี่ยมเปิด

<?php
$image = imagecreatetruecolor(700, 300);
$blue = imagecolorallocate($image, 0, 255, 255);
$points = [60, 130, 130, 230, 280, 230, 350, 130, 210, 30, 60, 130];
imageopenpolygon($image, $points, 6, $blue);
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>

ผลลัพธ์

PHP – วาด Open Polygon ด้วย imageopenpolygon()