用php imagemagick绘制圆圈

时间:2014-09-06 13:23:50

标签: php image imagemagick

我只是想了解如何使用php5 imagemagick绘制圆圈的基本概念。 我看了一下页面,http://php.net/manual/en/imagickdraw.circle.php 但那里的例子太混乱了。我想画一个圆圈然后弄乱它。有人能给我一个简单的php5 imagemagick圈子示例吗?

我试过了:

<?php
header("Content-type: image/jpeg");
$circle = new ImagickDraw();
$draw->circle (10, 10, 60, 10);
//echo $circle;
?>

任何众多的变种,但我不能画一个圆圈。

2 个答案:

答案 0 :(得分:1)

我希望这是你正在寻找的东西:

<?php
$draw = new ImagickDraw ();
//given that $x and $y are the coordinates of the centre, and $r the radius:
$draw->circle ($x, $y, $x + $r, $y);
?>

答案 1 :(得分:1)

Danak在php聊天页面上为我提供了这个链接,它提供了一个活跃的例子。 http://www.phpimagick.com/ImagickDraw/circle

变量名称简明扼要,具有描述性, 这个例子让我很容易理解发生了什么。

function circle($strokeColor, $fillColor, $backgroundColor, $originX, $originY, $endX, $endY) {

    //Create a ImagickDraw object to draw into.
    $draw = new \ImagickDraw();

    $strokeColor = new \ImagickPixel($strokeColor);
    $fillColor = new \ImagickPixel($fillColor);

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

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

    $draw->circle($originX, $originY, $endX, $endY);

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

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