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


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

ImagickDraw::setStrokeColor() 函数是 PHP 中的一个内置函数,用于设置用于描边对象轮廓的颜色。

用法:

bool ImagickDraw::setStrokeColor( $stroke_pixel )

参数:该函数接受用于保存颜色值的单个参数 $stroke_pixel。

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

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



程序1:


<?php
  
// require_once('path/vendor/autoload.php');
   
// Create an ImagickDraw object
$draw = new \ImagickDraw();
   
// Set stroke opacity
$draw->setStrokeOpacity(1);
   
// Set stroke color
$draw->setStrokeColor('Black');
   
// Set stroke opacity
$draw->setStrokeOpacity(0.8);
   
// Set stroke width
$draw->setStrokeWidth(10);
   
// Set Stroke Line Join
$draw->setStrokeLineJoin(Imagick::LINEJOIN_ROUND);
   
// Set Fill Color
$draw->setFillColor('lightgreen');
       
// Set Stroke Miter Limit
$draw->setStrokeMiterLimit(40 * 12);
   
$points = [
        ['x' => 50 * 6, 'y' => 10 * 5],
        ['x' => 20 * 7, 'y' => 30 * 5], 
        ['x' => 60 * 8, 'y' => 50 * 5], 
        ['x' => 70 * 3, 'y' => 15 * 5],
    ];
   
// Draw a polygon
$draw->polygon($points);
   
// Create a new Imagick object
$image = new \Imagick();
   
// Set image dimensions
$image->newImage(500, 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();
?>

输出:

程序2:


<?php
  
// require_once('path/vendor/autoload.php');
   
// Create an ImagickDraw object 
$draw = new \ImagickDraw();
   
// Set the stroke color
$draw->setStrokeColor('Green');
   
// Set Fill Color
$draw->setFillColor('Red');
   
// Set the stroke width
$draw->setStrokeWidth(7);
   
// Draw the rectangle
$draw->rectangle(40, 30, 200, 260);
   
// Create new Imagick object 
$image = new \Imagick();
   
// Set the image dimension
$image->newImage(300, 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.setstrokecolor.php




相关用法


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