ImagickDraw::pushClipPath()函數是PHP中的內置函數,用於啟動clip-path定義。剪切路徑用於創建剪切區域,該剪切區域決定應顯示圖像的哪一部分。顯示區域內部的零件,而隱藏外部的零件。
用法:
bool ImagickDraw::pushClipPath( string $clip_mask_id )
參數:該函數接受單個參數$clip_mask_id,該參數保存剪輯路徑的名稱。
返回值:成功時此函數返回TRUE。
以下示例程序旨在說明PHP中的ImagickDraw::pushClipPath()函數:
程序1:
<?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();
// Set the stroke color
$draw->setStrokeColor('blue');
// Set the fill color
$draw->setFillColor('cyan');
// Set the stroke width
$draw->setStrokeWidth(2);
// Push the clip path
$draw->pushClipPath('testClipPath');
// Create a rectangle which is
// the area to be clipped
$draw->rectangle(0, 0, 300, 300);
// Pop the clip path
$draw->popClipPath();
// Set the clip path
$draw->setClipPath('testClipPath');
$draw->circle(150, 50, 300, 150);
// 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();
// Set the fill color
$draw->setFillColor('green');
// Set the font size
$draw->setFontSize(90);
// Push the clip path
$draw->pushClipPath('testClipPath');
// Create a circle which is
// the area to be clipped
$draw->circle(200, 200, 300, 300);
// Pop the clip path
$draw->popClipPath();
// Set the clip path
$draw->setClipPath('testClipPath');
// Annotate a text
$draw->annotation(115, 200, 'GeeksforGeeks');
// 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.pushclippath.php
相關用法
- PHP ImagickDraw arc()用法及代碼示例
- PHP ImagickDraw pop()用法及代碼示例
- PHP ImagickDraw pathCurveToQuadraticBezierSmoothAbsolute()用法及代碼示例
- PHP ImagickDraw setStrokeMiterLimit()用法及代碼示例
- PHP ImagickDraw getStrokeMiterLimit()用法及代碼示例
- PHP ImagickDraw setFontSize()用法及代碼示例
- PHP ImagickDraw pathStart()用法及代碼示例
- PHP ImagickDraw getStrokeLineJoin()用法及代碼示例
- PHP ImagickDraw getStrokeLineCap()用法及代碼示例
- PHP ImagickDraw setFontWeight()用法及代碼示例
- PHP ImagickDraw setStrokeLineCap()用法及代碼示例
- PHP ImagickDraw setTextAntialias()用法及代碼示例
- PHP ImagickDraw setTextDecoration()用法及代碼示例
- PHP ImagickDraw setTextUnderColor()用法及代碼示例
- PHP ImagickDraw polygon()用法及代碼示例
注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | ImagickDraw pushClipPath() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。