當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。