首頁  >  文章  >  後端開發  >  如何使用PHP中的imgesetthickness()函數為線條繪製設定影像厚度?

如何使用PHP中的imgesetthickness()函數為線條繪製設定影像厚度?

WBOY
WBOY轉載
2023-09-08 15:49:01945瀏覽

imagesetthickness()是PHP中的內建函數,用來設定線條繪製的粗細。

Syntax

bool imagesetthickness($image, $thickness)

參數

imagesetthickness()接受兩個參數− $image和$thickness。

  • $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(&#39;Content-Type: image/png&#39;);
   imagepng($img);
   imagedestroy($img);
?>

輸出

如何使用PHP中的imgesetthickness()函數為線條繪製設定影像厚度?

#範例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(&#39;Content-Type: image/png&#39;);
   imagepng($img);
   imagedestroy($img);
?>

輸出

如何使用PHP中的imgesetthickness()函數為線條繪製設定影像厚度?

以上是如何使用PHP中的imgesetthickness()函數為線條繪製設定影像厚度?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除