如何使用 PHP 中的 imgesetthickness() 函式設定線描的影像厚度?


imagesetthickness() 是 PHP 中的一個內建函式,用於設定線描的厚度。

語法

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('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);
?>

輸出

更新於: 09-Aug-2021

308 次瀏覽

開啟你的事業

完成課程並獲得認證

開始學習
廣告
© . All rights reserved.