如何使用 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.