在 $draw->pathStart() 和 $draw->pathFinish() 之間,您需要先使用 $draw->pathMoveToAbsolute(x, y) 初始化位置。所有後續對「路徑函式」(包括絕對函式)的呼叫都會繼續路徑。
我原本以為 pathStart 會接受起始座標,而且我花了一段時間才意識到需要使用不同的函式來初始化。
(PECL imagick 2, PECL imagick 3)
ImagickDraw::pathStart — 宣告路徑繪圖列表的開始
此函式目前沒有文件記錄;只有其引數列表可用。
宣告路徑繪圖列表的開始,並由相符的 DrawPathFinish() 命令終止。所有其他 DrawPath 命令都必須包含在 a 和 a DrawPathFinish() 命令之間。這是因為路徑繪圖命令是從屬命令,它們本身不會運作。
不回傳任何值。
範例 1 ImagickDraw::pathStart() 範例
<?php
function pathStart($strokeColor, $fillColor, $backgroundColor) {
$draw = new \ImagickDraw();
$draw->setStrokeOpacity(1);
$draw->setStrokeColor($strokeColor);
$draw->setFillColor($fillColor);
$draw->setStrokeWidth(2);
$draw->setFontSize(72);
$draw->pathStart();
$draw->pathMoveToAbsolute(50, 50);
$draw->pathLineToAbsolute(100, 50);
$draw->pathLineToRelative(0, 50);
$draw->pathLineToHorizontalRelative(-50);
$draw->pathFinish();
$draw->pathStart();
$draw->pathMoveToAbsolute(50, 50);
$draw->pathMoveToRelative(300, 0);
$draw->pathLineToRelative(50, 0);
$draw->pathLineToVerticalRelative(50);
$draw->pathLineToHorizontalAbsolute(350);
$draw->pathclose();
$draw->pathFinish();
$draw->pathStart();
$draw->pathMoveToAbsolute(50, 300);
$draw->pathCurveToAbsolute(50, 300, 100, 200, 300, 300);
$draw->pathLineToVerticalAbsolute(350);
$draw->pathFinish();
$imagick = new \Imagick();
$imagick->newImage(500, 500, $backgroundColor);
$imagick->setImageFormat("png");
$imagick->drawImage($draw);
header("Content-Type: image/png");
echo $imagick->getImageBlob();
}
?>