当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


PHP ImagickDraw setStrokeAlpha()用法及代码示例

ImagickDraw::setStrokeAlpha() 函数是 PHP 中的一个内置函数,用于指定描边对象轮廓的不透明度。

用法:

bool ImagickDraw::setStrokeAlpha( $opacity )

参数:此函数接受单个参数 opacity,用于指定笔划对象的透明度。它是浮点值,介于 0 和 1 之间。

返回值:该函数不返回任何值。

以下示例程序旨在说明 PHP 中的 ImagickDraw::setStrokeAlpha() 函数:



程序1:


<?php
   
// require_once('path/vendor/autoload.php');
   
// Create an Imagick Draw object
$draw = new \ImagickDraw();
   
// Set the stroke color
$strokeColor = new \ImagickPixel('Green');
   
// Set the fill color
$fillColor = new \ImagickPixel('Red');
   
// Set the stroke color
$draw->setStrokeColor('Green');
   
// Set the Fill Color
$draw->setFillColor('Red');
   
// Set the stroke width
$draw->setStrokeWidth(5);
  
// Set the stroke opacity
$draw->setStrokeOpacity(0.5);
   
$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 imagick object
$imagick = new \Imagick();
   
// Set the image dimensions
$imagick->newImage(300, 300, 'White');
   
// Set the image format
$imagick->setImageFormat("png");
   
// Draw the image
$imagick->drawImage($draw);
header("Content-Type:image/png");
   
// Display the image
echo $imagick->getImageBlob();
?>

输出:

程序2:


<?php
  
// require_once('path/vendor/autoload.php');
  
// Create an ImagickDraw object
  
$draw = new \ImagickDraw();
  
// Set the Stroke Color 
$draw->setStrokeColor('Green');
  
// Set the Fill Color
$draw->setFillColor('Red');
  
// Set the stroke width
$draw->setStrokeWidth(7);
  
// Set the stroke opacity
$draw->setStrokeOpacity(0.5);
  
// Draw the rectangle
$draw->rectangle(40, 30, 200, 260);
  
// Create an Imagick object 
$image = new \Imagick();
  
// Set the image dimensions
$image->newImage(250, 300, 'White');
  
// Set the image format
$image->setImageFormat("png");
  
// Draw the image
$image->drawImage($draw);
header("Content-Type:image/png");
  
// Display the image 
echo $image->getImageBlob();
?>

输出:

参考: http://php.net/manual/en/imagickdraw.setstrokealpha.php




相关用法


注:本文由纯净天空筛选整理自sarthak_ishu11大神的英文原创作品 PHP | ImagickDraw setStrokeAlpha() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。