imageline() เป็นฟังก์ชัน inbuilt ใน PHP ที่ใช้ในการวาดเส้นระหว่างจุดสองจุดที่กำหนด
ไวยากรณ์
bool imageline(resource $image, int $x1, int $y1,int $x2, int $y2, int $color)
พารามิเตอร์
imageline() ใช้พารามิเตอร์ที่แตกต่างกันหกตัว:$image, $x1, $y1, $x2, $y2 and $color.
-
$image − ระบุทรัพยากรรูปภาพที่จะใช้งาน
-
$x1 − ระบุพิกัด x เริ่มต้น
-
$y1 − ระบุพิกัด y เริ่มต้น
-
$x2 − ระบุพิกัด x สิ้นสุด
-
$y2 − ระบุพิกัด y ลงท้าย
-
$สี − ระบุสีเส้นและตัวระบุสีที่สร้างโดยใช้ imagecolorallocate() ฟังก์ชัน
คืนค่า
imageline() คืนค่า True เมื่อสำเร็จหรือ False เมื่อล้มเหลว
ตัวอย่างที่ 1 − เพิ่มบรรทัดให้กับรูปภาพ
<?php
// Create an image using imagecreatefrompng() function
$img = imagecreatefrompng('C:\xampp\htdocs\test\515.png');
// allocated the line color
$text_color = imagecolorallocate($img, 255, 255, 0);
// Set the thickness of the line
imagesetthickness($img, 5);
// Add a line using imageline() function.
imageline($img, 80, 300, 1140, 300, $text_color);
// Output of the image
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?> ผลลัพธ์

ตัวอย่างที่ 2
<?php
// Create an image using imagecreate() function
$img = imagecreate(700, 300);
// Allocate the colors
$grey = imagecolorallocate($img, 122, 122, 122);
$blue = imagecolorallocate($img, 0, 0, 255);
// Set the thickness of the line
imagesetthickness($img, 15);
// Add a grey background color
imageline($img, 0, 0, 550, 400, $grey);
// Add a blue line
imageline($img, 0, 0, 550, 400, $blue);
// Output the image
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?> ผลลัพธ์
