Reputation: 1784
I just want to get the basic idea of how to draw a circle with php5 imagemagick. I have looked at the page, http://php.net/manual/en/imagickdraw.circle.php but the example there is too confusing. I want to just draw a circle then mess around with that. Can someone give me a simple php5 imagemagick circle example?
I have tried:
<?php
header("Content-type: image/jpeg");
$circle = new ImagickDraw();
$draw->circle (10, 10, 60, 10);
//echo $circle;
?>
any numerous variants, but I cant get a circle drawn.
Upvotes: 3
Views: 3620
Reputation: 1784
Danak on the php chat page provided me with this link, Which provides an active example. http://www.phpimagick.com/ImagickDraw/circle
The variable names are concise and descriptive, and the example makes it easy for me to understand what is going on.
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();
}
Upvotes: 1
Reputation: 691
I hope this is what you're looking for:
<?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);
?>
Upvotes: 1