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


PHP imagesetthickness()用法及代碼示例

imagesetthickness()函數是PHP中的內置函數,用於設置線條繪製的厚度。

用法:

bool imagesetthickness( $image, $thickness )

參數:該函數接受上述和以下描述的兩個參數:


  • $image:它由圖像創建函數之一(例如imagecreatetruecolor())返回。它用於創建圖像的尺寸。
  • $thickness:此參數用於設置像素的厚度。

返回值:如果成功,此函數返回True;如果失敗,則返回False。

以下示例程序旨在說明PHP中的imagesetthickness()函數:

示例1:

<?php 
  
// Create an image of given size 
$im = imagecreatetruecolor(400, 300); 
$green = imagecolorallocate($im, 0, 153, 0); 
$white = imagecolorallocate($im, 0xff, 0xff, 0xff); 
  
// Set the background to be white 
imagefilledrectangle($im, 0, 0, 400, 300, $green); 
  
// Set the line thickness to 5 
imagesetthickness($im, 5); 
  
// Draw the rectangle 
imagerectangle($im, 50, 50, 350, 250, $white); 
  
// Output image to the browser 
header('Content-Type: image/png'); 
  
imagepng($im); 
imagedestroy($im); 
?>

輸出:

示例2:

<?php 
   
// Create an image of given size 
$im = imagecreatetruecolor(400, 100); 
$green = imagecolorallocate($im, 0, 153, 0); 
$white = imagecolorallocate($im, 0xff, 0xff, 0xff); 
   
// Set the background to be white 
imagefilledrectangle($im, 0, 0, 400, 300, $green); 
   
// Set the line thickness to 15 
imagesetthickness($im, 15); 
  
// Draw the line 
imageline($im, 50, 50, 350, 50, $white); 
   
// Output image to the browser 
header('Content-Type: image/png'); 
   
imagepng($im); 
imagedestroy($im); 
?>

輸出:

參考: http://php.net/manual/en/function.imagesetthickness.php



相關用法


注:本文由純淨天空篩選整理自Mahadev99大神的英文原創作品 PHP | imagesetthickness() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。