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


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


ImagickDraw::pathClose()函数是PHP中的内置函数,用于将路径元素添加到当前路径,该路径元素通过绘制直线来关闭当前子路径。简而言之,它用于将笔画完全应用于所有边。

用法:

bool ImagickDraw::pathClose( void )

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


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

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

示例1:

<?php 
  
// Create a new imagick object 
$imagick = new Imagick(); 
  
// Create a image on imagick object 
$imagick->newImage(800, 250, 'black'); 
  
// Create a new ImagickDraw object 
$draw = new ImagickDraw(); 
  
// Set the stroke color 
$draw->setStrokeColor('white'); 
  
// Set the stroke width 
$draw->setStrokeWidth(5); 
  
// Create a shape with four corners using 
// paths with pathClose() function 
$draw->pathStart(); 
$draw->pathMoveToAbsolute(420, 50); 
$draw->pathMoveToRelative(20, 0); 
$draw->pathLineToRelative(50, 90); 
$draw->pathLineToVerticalRelative(30); 
$draw->pathLineToHorizontalAbsolute(250); 
$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, 'white'); 
  
// Create a new ImagickDraw object 
$draw = new ImagickDraw(); 
  
// Add texts to image 
$draw->annotation(100, 200, 'With pathClose()'); 
$draw->annotation(500, 200, 'Without pathClose()'); 
  
// Set the stroke color 
$draw->setStrokeColor('green'); 
  
// Set the stroke width 
$draw->setStrokeWidth(5); 
  
// Create a shape with three coreners using 
// paths (with pathClose()) 
$draw->pathStart(); 
$draw->pathMoveToAbsolute(20, 50); 
$draw->pathMoveToRelative(20, 0); 
$draw->pathLineToRelative(50, 90); 
$draw->pathLineToVerticalRelative(0); 
$draw->pathLineToHorizontalAbsolute(250); 
$draw->pathClose(); 
$draw->pathFinish(); 
  
// Create the same shape using 
// paths (without pathClose()) 
$draw->translate(400, 0); 
$draw->pathStart(); 
$draw->pathMoveToAbsolute(20, 50); 
$draw->pathMoveToRelative(20, 0); 
$draw->pathLineToRelative(50, 90); 
$draw->pathLineToVerticalRelative(0); 
$draw->pathLineToHorizontalAbsolute(250); 
$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.pathclose.php



相关用法


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