PHP Conference Japan 2024

ImagickDraw::arc

(PECL imagick 2, PECL imagick 3)

ImagickDraw::arc繪製弧線

說明

public ImagickDraw::arc(
    float $sx,
    float $sy,
    float $ex,
    float $ey,
    float $sd,
    float $ed
): bool
警告

此函式目前尚未文件化;僅提供其參數列表。

在影像上指定的邊界矩形內繪製弧線。

參數

sx

邊界矩形的起始 x 座標

sy

邊界矩形的起始 y 座標

ex

邊界矩形的結束 x 座標

ey

邊界矩形的結束 y 座標

sd

起始旋轉角度(度)

ed

結束旋轉角度(度)

傳回值

不傳回任何值。

範例

範例 1 ImagickDraw::arc() 範例

<?php
function arc($strokeColor, $fillColor, $backgroundColor, $startX, $startY, $endX, $endY, $startAngle, $endAngle) {

//建立一個 ImagickDraw 物件以繪製圖形。
$draw = new \ImagickDraw();
$draw->setStrokeWidth(1);
$draw->setStrokeColor($strokeColor);
$draw->setFillColor($fillColor);
$draw->setStrokeWidth(2);

$draw->arc($startX, $startY, $endX, $endY, $startAngle, $endAngle);

//建立一個影像物件,可將繪圖命令渲染到其中
$image = new \Imagick();
$image->newImage(IMAGE_WIDTH, IMAGE_HEIGHT, $backgroundColor);
$image->setImageFormat("png");

//將 ImagickDraw 物件中的繪圖命令
//渲染到影像中。
$image->drawImage($draw);

//將影像傳送到瀏覽器
header("Content-Type: image/png");
echo
$image->getImageBlob();
}

?>

新增註解

使用者貢獻的註解 1 則註解

skmanji at manji dot org
13 年前
您可以使用弧線和多邊形函式的組合來製作圓餅圖(其實應該要有內建的指令來做這件事)

<?php
// 建立新的畫布物件和白色影像
$canvas = new Imagick();
$canvas->newImage(600, 600, 'grey');

image_pie($canvas, 300, 300, 200, 0, 45, 'red');
image_pie($canvas, 300, 300, 200, 45, 125, 'green');
image_pie($canvas, 300, 300, 200, 125, 225, 'blue');
image_pie($canvas, 300, 300, 200, 225, 300, 'cyan');
image_pie($canvas, 300, 300, 200, 300, 360, 'orange');

// 輸出影像
$canvas->setImageFormat('png');
header("Content-Type: image/png");
echo
$canvas;
exit;

// 函式

function image_arc( &$canvas, $sx, $sy, $ex, $ey, $sd, $ed, $color = 'black' ) {

// 在畫布上繪製弧形
// $sx, $sy, $ex, $ey 指定一個以中心為原點的圓的邊界矩形
// $sd 和 $ed 指定起始和結束角度,以度為單位

$draw = new ImagickDraw();
$draw->setFillColor($color);
$draw->setStrokeColor($color);
$draw->setStrokeWidth(1);
$draw->arc($sx, $sy, $ex, $ey, $sd, $ed);
$canvas->drawImage($draw);
}

function
image_pie( &$canvas, $ox, $oy, $radius, $sd, $ed, $color = 'black' ) {

// 繪製扇形區塊
// $ox, $oy 指定圓心
// $sd 和 $ed 指定起始和結束角度,以度為單位
// 角度從 0 = 東方開始,順時針方向增加

// 位置 1 - 將度數轉換為弧度,並取得圓周上的第一個點
$x1 = $radius * cos($sd / 180 * 3.1416);
$y1 = $radius * sin($sd / 180 * 3.1416);

// 位置 2 - 將度數轉換為弧度,並取得圓周上的第二個點
$x2 = $radius * cos($ed / 180 * 3.1416);
$y2 = $radius * sin($ed / 180 * 3.1416);

// 繪製扇形三角形 - 指定 3 個點並繪製多邊形
$points = array(array('x' => $ox, 'y' => $oy), array('x' => $ox + $x1, 'y' => $oy + $y1), array('x' => $ox + $x2, 'y' => $oy + $y2));

image_polygon($canvas, $points, $color);

// 繪製對應的弧形以完成「扇形」區塊
image_arc($canvas, $ox - $radius, $oy - $radius, $ox + $radius, $oy + $radius, $sd, $ed, $color);
}

function
image_polygon( &$canvas, $points, $color = 'black' ) {

// 在畫布上繪製多邊形

$draw = new ImagickDraw();
$draw->setFillColor($color);
$draw->setStrokeColor($color);
$draw->setStrokeWidth(1);
$draw->polygon($points);
$canvas->drawImage($draw);
}

?>
To Top