Draw circle with php imagemagick
I just want to get a basic idea on how to draw a circle using php5 imagemagick. I've looked at the page, http://php.net/manual/en/imagickdraw.circle.php but the example is too confusing. I just want to draw a circle and then have a chat with it. Can anyone give me a simple php5 imagemagick circle example?
I tried:
<?php
header("Content-type: image/jpeg");
$circle = new ImagickDraw();
$draw->circle (10, 10, 60, 10);
//echo $circle;
?>
any numerous options, but I can't get the circle.
+3
j0h
source
to share
2 answers
Danak on the php chat page provided me with this link which provides an active example. http://www.phpimagick.com/ImagickDraw/circle
Variable names are short and descriptive, and this example makes it easier for me to understand what's 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();
}
+1
j0h
source
to share
Hope this is what you are 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);
?>
+1
Traian tatic
source
to share