PHP Conference Japan 2024

ImagickDraw::line

(PECL imagick 2, PECL imagick 3)

ImagickDraw::line繪製線條

說明

public ImagickDraw::line(
    float $sx,
    float $sy,
    float $ex,
    float $ey
): bool
警告

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

使用目前的筆觸顏色、筆觸不透明度和筆觸寬度在影像上繪製線條。

參數

sx

起始 x 座標

sy

起始 y 座標

ex

結束 x 座標

ey

結束 y 座標

回傳值

不回傳任何值。

範例

範例 1 ImagickDraw::line() 範例

<?php
function line($strokeColor, $fillColor, $backgroundColor) {

$draw = new \ImagickDraw();

$draw->setStrokeColor($strokeColor);
$draw->setFillColor($fillColor);

$draw->setStrokeWidth(2);
$draw->setFontSize(72);

$draw->line(125, 70, 100, 50);
$draw->line(350, 170, 100, 150);

$imagick = new \Imagick();
$imagick->newImage(500, 500, $backgroundColor);
$imagick->setImageFormat("png");
$imagick->drawImage($draw);

header("Content-Type: image/png");
echo
$imagick->getImageBlob();
}

?>

新增註解

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

GaryM at BinaryFarm dot com
14 年前
<?php

// 上述雷達螢幕的變體。
// 這會從中心點繪製隨機顏色的輻條

$width = 400;
$height = 400;

$image = new Imagick();
$image->newImage( $width, $height, new ImagickPixel( 'wheat' ) );
$draw = new ImagickDraw();
//$draw->setStrokeColor( new ImagickPixel( 'black' ) );

$rx = $width / 2;
$ry = $height / 2;
$total = 2*M_PI;
$part = $total / 16;
while(
$total > 0 )
{
$ex = $rx +$rx * sin( $total );
$ey = $ry +$ry * cos( $total );
$draw->line ( $rx, $ry, $ex, $ey );
$total -= $part;

// 我們需要三個十六進制數字來建立一個 RGB 顏色代碼,例如 '#FF33DD'。

$draw->setStrokeColor( get_random_color() );
}
$image->drawImage( $draw );
$image->setImageFormat( "png" );
header( "Content-Type: image/png" );
echo
$image;
exit;

function
get_random_color() // 感謝 Greg R. 提供這個漂亮的小函式。
{
for (
$i = 0; $i<6; $i++)
{
$c .= dechex(rand(0,15));
}
return
"#$c";
}
?>
To Top