當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP imgesetthickness()用法及代碼示例

imagesetthickness()是 PHP 中的一個內置函數,用於設置線條繪製的粗細。

用法

bool imagesetthickness($image, $thickness)

參數

imagesetthickness()接受兩個參數 -$圖像和$厚度。

  • $image− 該參數由imagecreatetruecolor() 等圖像創建函數返回。它用於創建圖像的大小。

  • $thickness− 此參數以像素為單位設置厚度。

返回值

imagesetthickness()成功時返回 True,失敗時返回 False。

例子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);
?>

輸出

例子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);
?>

輸出

相關用法


注:本文由純淨天空篩選整理自Urmila Samariya大神的英文原創作品 How to set the image thickness for line drawing using imgesetthickness() function in PHP?。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。