imagesetthickness() là hàm nội bộ trong PHP dùng để thiết lập độ dày cho vẽ đường thẳng.
Cú pháp
bool imagesetthickness(GdImage $image, int $thickness)
Tham số
imagesetthickness() nhận hai tham số: $image và $thickness.
$image – Trả về bởi hàm tạo ảnh như imagecreatetruecolor(). Dùng để tạo kích thước ảnh.
$thickness – Độ dày tính bằng pixel.
Giá trị trả về
imagesetthickness() trả về true khi thành công và false khi thất bại.
Ví dụ 1 – Vẽ hình chữ nhật dày 10px
<?php
$img = imagecreatetruecolor(700, 300);
$gray = imagecolorallocate($img, 0, 0, 255);
$white = imagecolorallocate($img, 0xff, 0xff, 0xff);
// Màu nền xám
imagefilledrectangle($img, 0, 0, 700, 300, $gray);
// Độ dày nét 10
imagesetthickness($img, 10);
// Vẽ hình chữ nhật
imagerectangle($img, 30, 30, 200, 150, $white);
// Xuất ảnh
header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
?>
Kết quả

Ví dụ 2 – Vẽ đường thẳng dày 50px
<?php
$img = imagecreatetruecolor(700, 300);
$blue = imagecolorallocate($img, 0, 0, 255);
$white = imagecolorallocate($img, 0xff, 0xff, 0xff);
// Màu nền trắng
imagefilledrectangle($img, 0, 0, 300, 200, $blue);
// Độ dày nét 50
imagesetthickness($img, 50);
// Vẽ đường thẳng trắng
imageline($img, 50, 50, 250, 50, $white);
header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
?>
Kết quả
