📜  PHP | imagickdraw setFillOpacity()函数

📅  最后修改于: 2022-05-13 01:56:51.226000             🧑  作者: Mango

PHP | imagickdraw setFillOpacity()函数

ImagickDraw::setFillOpacity()函数是PHP中的一个内置函数,用于设置使用填充颜色或填充纹理绘制时使用的不透明度。
句法:

bool ImagickDraw::setFillOpacity( $fillOpacity ) 

参数:此函数接受单个参数$fillOpacity ,用于将不透明度的值保存为浮点类型。
返回值:此函数不返回任何值。
下面的程序说明了PHP中的ImagickDraw::setFillOpacity()函数
方案一:

php
setStrokeColor('Green');
  
// Use setFillColor() Function
$draw->setFillColor('Red');
  
// Use setFillOpacity() Function
$draw->setFillOpacity(0.2);
  
$draw->setStrokeWidth(7);
  
// Create rectangle
$draw->rectangle(40, 30, 200, 260);
  
// Use setFillColor() Function
$draw->setFillColor('Red');
 
// Create rectangle of given size
$draw->rectangle(260, 30, 400, 260);
  
// Create an Imagick object
$image = new \Imagick();
     
$image->newImage(500, 300, 'white');
 
// Set the image format
$image->setImageFormat("png");
  
// Render the draw commands in the
// ImagickDraw object into the image.
$image->drawImage($draw);
  
// Send the image to the browser
header("Content-Type: image/png");
echo $image->getImageBlob();
  
?>


php
setStrokeColor('Green');
 
// Set the filled color
$draw->setFillColor('Red');
      
// Use setFillOpacity() Function
$draw->setFillOpacity(0.5);
 
// Set the stroke width
$draw->setStrokeWidth(2);
  
$smoothPointsSet = [ [
          ['x' => 10.0 * 5, 'y' => 10.0 * 5],
          ['x' => 30.0 * 5, 'y' => 90.0 * 5],
          ['x' => 25.0 * 5, 'y' => 10.0 * 5],
          ['x' => 50.0 * 5, 'y' => 50.0 * 5], ] ];
  
foreach ($smoothPointsSet as $points) {
    $draw->bezier($points);
}
 
// Create an image object
$imagick = new \Imagick();
 
$imagick->newImage(300, 300, 'White');
 
// Set the image format
$imagick->setImageFormat("png");
  
// Render the draw commands in the
// ImagickDraw object into the image.
$imagick->drawImage($draw);
  
// Send the image to the browser
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>


输出:

设置填充不透明度

方案二:

PHP

setStrokeColor('Green');
 
// Set the filled color
$draw->setFillColor('Red');
      
// Use setFillOpacity() Function
$draw->setFillOpacity(0.5);
 
// Set the stroke width
$draw->setStrokeWidth(2);
  
$smoothPointsSet = [ [
          ['x' => 10.0 * 5, 'y' => 10.0 * 5],
          ['x' => 30.0 * 5, 'y' => 90.0 * 5],
          ['x' => 25.0 * 5, 'y' => 10.0 * 5],
          ['x' => 50.0 * 5, 'y' => 50.0 * 5], ] ];
  
foreach ($smoothPointsSet as $points) {
    $draw->bezier($points);
}
 
// Create an image object
$imagick = new \Imagick();
 
$imagick->newImage(300, 300, 'White');
 
// Set the image format
$imagick->setImageFormat("png");
  
// Render the draw commands in the
// ImagickDraw object into the image.
$imagick->drawImage($draw);
  
// Send the image to the browser
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>

输出:

设置填充不透明度

参考: http: PHP。 PHP