Độ dày hình ảnh () là một hàm có sẵn trong PHP được sử dụng để đặt độ dày cho bản vẽ đường thẳng.
Cú pháp
bool imagesetthickness($image, $thickness)
Tham số
Độ dày hình ảnh () chấp nhận hai tham số - $ hình ảnh và $ độ dày.
-
$ hình ảnh - Tham số này được trả về bởi một hàm tạo ảnh chẳng hạn như imageecreatetruecolor (). Nó được sử dụng để tạo kích thước của hình ảnh.
-
Độ dày $ - Tham số này đặt độ dày tính bằng pixel.
Giá trị trả lại
Độ dày hình ảnh () trả về Đúng khi thành công và Sai khi thất bại.
Ví dụ 1
<?php
// Create an image of a given size
$img = imagecreatetruecolor(700, 300);
$gray = imagecolorallocate($img, 0, 0, 255);
$white = imagecolorallocate($img, 0xff, 0xff, 0xff);
// Set the gray background color
imagefilledrectangle($img, 0, 0, 700, 300, $gray);
// Set the line thickness to 10
imagesetthickness($img, 10);
// Draw the rectangle
imagerectangle($img, 30, 30, 200, 150, $white);
// Output image to the browser
header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
?> Đầu ra
Ví dụ 2
<?php
// Create an image of given size using imagecreatetruecolor() function
$img = imagecreatetruecolor(700, 300);
$blue = imagecolorallocate($img, 0, 0, 255);
$white = imagecolorallocate($img, 0xff, 0xff, 0xff);
// Set the white background-color
imagefilledrectangle($img, 0, 0, 300, 200, $blue);
// Set the line thickness to 50
imagesetthickness($img, 50);
// Draw the white line
imageline($img, 50, 50, 250, 50, $white);
// Output image to the browser
header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
?> Đầu ra