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


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


ImagickDraw::pathFinish()函数是PHP中的一个内置函数,用于终止当前路径。当要在图像中绘制多个路径时,这是必需的。

用法:

bool ImagickDraw::pathFinish( void )

参数:此函数不接受任何参数。


返回值:成功时此函数返回TRUE。

异常:该函数在错误时引发ImagickException。

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

示例1:

<?php 
  
// Create a new imagick object 
$imagick = new Imagick(); 
  
// Create a image on imagick object 
$imagick->newImage(800, 250, '#1a65f0'); 
  
// Create a new ImagickDraw object 
$draw = new ImagickDraw(); 
  
$draw->setFillColor('#2fceeb'); 
  
// Set the stroke color 
$draw->setStrokeColor('black'); 
  
// Set the stroke width 
$draw->setStrokeWidth(15); 
  
// Create a path 
$draw->pathStart(); 
$draw->pathMoveToAbsolute(50, 50); 
$draw->pathLineToAbsolute(100, 50); 
$draw->pathLineToRelative(0, 50); 
$draw->pathLineToHorizontalRelative(-50); 
$draw->pathFinish(); 
  
// Create another path 
$draw->pathStart(); 
$draw->pathMoveToAbsolute(50, 50); 
$draw->pathMoveToRelative(300, 0); 
$draw->pathLineToRelative(50, 0); 
$draw->pathLineToVerticalRelative(50); 
$draw->pathLineToHorizontalAbsolute(350); 
$draw->pathclose(); 
$draw->pathFinish(); 
  
// Render the draw commands 
$imagick->drawImage($draw); 
  
// Show the output 
$imagick->setImageFormat('png'); 
header("Content-Type: image/png"); 
echo $imagick->getImageBlob(); 
?>

输出:

示例2:

<?php 
  
// Create a new imagick object 
$imagick = new Imagick(); 
  
// Create a image on imagick object 
$imagick->newImage(800, 250, '#1a65f0'); 
  
// Create a new ImagickDraw object 
$draw = new ImagickDraw(); 
  
$draw->setFillColor('red'); 
  
// Set the stroke color 
$draw->setStrokeColor('black'); 
  
// Set the stroke width 
$draw->setStrokeWidth(1); 
  
// Create a path 
$draw->pathStart(); 
$draw->pathMoveToAbsolute(50, 50); 
$draw->pathLineToAbsolute(100, 150); 
$draw->pathLineToRelative(0, 50); 
$draw->pathLineToHorizontalRelative(-50); 
$draw->pathFinish(); 
  
$x = 0; 
for ($x; $x < 10; $x++) { 
  
    // Create another path 
    $draw->pathStart(); 
    $draw->pathMoveToAbsolute(50, 150); 
    $draw->pathMoveToRelative($x * 100, 0); 
    $draw->pathLineToRelative(50, 0); 
    $draw->pathLineToVerticalRelative(50); 
    $draw->pathLineToHorizontalAbsolute(350); 
    $draw->pathclose(); 
    $draw->pathFinish(); 
} 
  
// Render the draw commands 
$imagick->drawImage($draw); 
  
// Show the output 
$imagick->setImageFormat('png'); 
header("Content-Type: image/png"); 
echo $imagick->getImageBlob(); 
?>

输出:

参考: https://www.php.net/manual/en/imagickdraw.pathfinish.php



相关用法


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