ImagickDraw::circle

(PECL imagick 2, PECL imagick 3)

ImagickDraw::circleDessine un cercle

Description

public ImagickDraw::circle(
    float $ox,
    float $oy,
    float $px,
    float $py
): bool
Avertissement

Cette fonction est actuellement non documentée ; seule la liste des arguments est disponible.

Dessine un cercle.

Liste de paramètres

ox

abscisse de l'origine

oy

ordonnée de l'origine

px

abscisse du périmètre

py

ordonnée du périmètre

Valeurs de retour

Aucune valeur n'est retournée.

Exemples

Exemple #1 Exemple avec ImagickDraw::circle()

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

//Création d'un objet ImagickDraw.
$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();
}

?>

add a note add a note

User Contributed Notes 2 notes

up
7
SkepticaLee
10 years ago
The four values required here are a bit confusing. After all, a circle is defined by three values: the x, y coordinates of the centre, and the radius, r.

The fourth value is redundant, but has to be given, otherwise the function fails. One way of coping with this redundancy is:

<?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);
?>

There are any number of actions which are synonymous with the last, including:
<?php
$draw
->circle ($x, $y, $x, $y + $r);
$draw->circle ($x, $y, $x - $r, $y);
$draw->circle ($x, $y, $x, $y - $r);
// etc, etc.
?>

Hope this helps.
up
-7
christian dot reinecke at web dot de
15 years ago
This example creates a circle, one part green, one part red using kind of masks for transparency, which you might know from Photoshop. drawImage() is a quick helper for debug output (see code comments) to help you reproduce the process.

<?php
function drawImage(Imagick $im) {
   
$im->setCompressionQuality(100);
   
$im->setImageFormat("jpg");
   
header("Content-Type: image/" . $im->getImageFormat());
    echo
$im;
    exit;
}

// define red/green layer
$layer1 = new Imagick();
$layer1->newImage(100, 100, "none");

$red = new ImagickDraw();
$red->setFillColor("#FF0000");
$red->rectangle(0, 0, 50, 100);

$green = new ImagickDraw();
$green->setFillColor("#00FF00");
$green->rectangle(50, 0, 100, 100);

$layer1->drawImage($red);
$layer1->drawImage($green);

# debug output: two rectangles
# drawImage($layer1);

// define circle mask
$layer2 = new Imagick();
$layer2->newImage(100, 100, "none");

$circle = new ImagickDraw();
$circle->setFillColor("#FFFFFF");
$circle->circle(50, 50, 48, 98);

$layer2->drawImage($circle);

# debug output: the mask
# drawImage($layer2);

// use mask
$layer1->compositeImage($layer2, Imagick::COMPOSITE_DSTIN, 0, 0);

# debug output: the result of our mask usage
# drawImage($layer1);

// define background
$layer3 = new Imagick();
$layer3->newImage(100, 100, "none");

$layer3->compositeImage($layer1, Imagick::COMPOSITE_DEFAULT, 0, 0);

// define ring as background
$layer4 = new Imagick();
$layer4->newImage(100, 100, "white"); // this is our background

$ring1 = new ImagickDraw();
$ring1->setFillColor("black");
$ring1->circle(50, 50, 50, 99);

$layer4->drawImage($ring1);

# debug output: this is a black circle (not our mask, which is similar, but a little bit smaller)
# drawImage($layer4);

// use black circle as background (this creates our circle border)
$layer4->compositeImage($layer3, Imagick::COMPOSITE_DEFAULT, 0, 0);

# debug output: here we go with our circle border
# drawImage($layer4);

// draw separator between red and green rectangle (now semi circles)
$line = new ImagickDraw();
$line->setStrokeWidth(1);
$line->setStrokeColor("black");
$line->line(50, 1, 50, 99);

// add our separator line
$layer4->drawImage($line);

drawImage($layer4);
?>

To understand how the COMPOSITE_* constants effect the image merging process, see here:
http://www.imagemagick.org/Usage/compose/#duff-porter
To Top