ฟังก์ชัน imageline() ใช้วาดเส้นตรงระหว่างจุดสองจุดที่กำหนด
รูปแบบการใช้งาน (Syntax)
bool imageline(GdImage $image, int $x1, int $y1, int $x2, int $y2, int $color)
พารามิเตอร์
- $image – GdImage resource
- $x1, $y1 – พิกัดจุดเริ่มต้น
- $x2, $y2 – พิกัดจุดสิ้นสุด
- $color – สีเส้น (จาก imagecolorallocate())
ค่าที่คืนกลับ
คืน true เมื่อสำเร็จ false เมื่อล้มเหลว
ตัวอย่าง 1: วาดเส้นบนรูปภาพที่มีอยู่
<?php
$img = imagecreatefrompng('C:\xampp\htdocs\test\515.png');
$text_color = imagecolorallocate($img, 255, 255, 0);
imagesetthickness($img, 5);
imageline($img, 80, 300, 1140, 300, $text_color);
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?>
ผลลัพธ์

ตัวอย่าง 2: วาดเส้นทับกันสองสี
<?php
$img = imagecreate(700, 300);
$grey = imagecolorallocate($img, 122, 122, 122);
$blue = imagecolorallocate($img, 0, 0, 255);
imagesetthickness($img, 15);
imageline($img, 0, 0, 550, 400, $grey);
imageline($img, 0, 0, 550, 400, $blue);
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?>
ผลลัพธ์
