ฟังก์ชัน imagesetthickness() ใช้ตั้งค่าความหนาของเส้นสำหรับการวาด (imageline, imagerectangle, ฯลฯ)
รูปแบบการใช้งาน (Syntax)
bool imagesetthickness(GdImage $image, int $thickness)
พารามิเตอร์
- $image – GdImage resource จาก imagecreatetruecolor()
- $thickness – ความหนาเป็น pixel
ค่าที่คืนกลับ
คืน true เมื่อสำเร็จ false เมื่อล้มเหลว
ตัวอย่าง 1: วาดสี่เหลี่ยมเส้นหนา 10px
<?php
$img = imagecreatetruecolor(700, 300);
$gray = imagecolorallocate($img, 0, 0, 255);
$white = imagecolorallocate($img, 0xff, 0xff, 0xff);
imagefilledrectangle($img, 0, 0, 700, 300, $gray);
imagesetthickness($img, 10);
imagerectangle($img, 30, 30, 200, 150, $white);
header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
?>
ผลลัพธ์

ตัวอย่าง 2: วาดเส้นหนา 50px
<?php
$img = imagecreatetruecolor(700, 300);
$blue = imagecolorallocate($img, 0, 0, 255);
$white = imagecolorallocate($img, 0xff, 0xff, 0xff);
imagefilledrectangle($img, 0, 0, 300, 200, $blue);
imagesetthickness($img, 50);
imageline($img, 50, 50, 250, 50, $white);
header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
?>
ผลลัพธ์
