Content · Web Development · PHP

PHP ImagickDraw::circle() Method: Usage and Examples

PHP ImagickDraw::circle() Method: Usage and Examples: Draws a circle using its center and another point on the circumference.

1 views Published Oct 17, 2026 Updated Oct 17, 2026 admin

ImagickDraw prepares vector drawing instructions and style settings; an Imagick image must receive the drawing instructions before the result becomes visible.

What Is ImagickDraw::circle in PHP?


Draws a circle using its center and another point on the circumference.

Simplified call syntax (optional overload parameters are omitted where applicable):

ImagickDraw::circle(float $origin_x, float $origin_y, float $perimeter_x, float $perimeter_y): bool
  • $origin_x — Horizontal coordinate of the shape center.
  • $origin_y — Vertical coordinate of the shape center.
  • $perimeter_x — Horizontal coordinate of a point on the circle.
  • $perimeter_y — Vertical coordinate of a point on the circle.

Requirement: The PECL Imagick extension and ImageMagick with relevant format support must be available.

Example 1: Understanding the Basic Behavior


<?php

$drawing = new ImagickDraw();
$drawing->setStrokeWidth(1);
$drawing->circle(30, 30, 50, 30);
$image = new Imagick();
$image->newImage(150, 90, new ImagickPixel("white"));
$image->drawImage($drawing);
echo $image->getImageWidth();

Requires PECL Imagick and format support in ImageMagick.

Explanation: Draws a circle using its center and another point on the circumference.

Example 2: Testing Another Case


<?php

$drawing = new ImagickDraw();
$drawing->setStrokeWidth(2);
$drawing->circle(30, 30, 50, 30);
$image = new Imagick();
$image->newImage(150, 90, new ImagickPixel("white"));
$image->drawImage($drawing);
echo $image->getImageWidth();

Requires PECL Imagick and format support in ImageMagick.

Explanation: A drawing instruction or setting does not create a visible image until you render the drawing context with Imagick::drawImage().

Practical Example: Applying the Operation


<?php

$drawing = new ImagickDraw();
$drawing->setStrokeWidth(3);
$drawing->circle(30, 30, 50, 30);
$image = new Imagick();
$image->newImage(150, 90, new ImagickPixel("white"));
$image->drawImage($drawing);
echo $image->getImageWidth();

Requires PECL Imagick and format support in ImageMagick.

Explanation: Coordinate values use pixels in the image canvas. Font availability and ImageMagick configuration can vary.

Important Behavior and Edge Cases


  • A drawing instruction or setting does not create a visible image until you render the drawing context with Imagick::drawImage().
  • Coordinate values use pixels in the image canvas. Font availability and ImageMagick configuration can vary.

Comparison With Related Approaches


ApproachWhen to Use It
ImagickDraw::circleDraws a circle using its center and another point on the circumference.
Imagick::drawImage()ImagickDraw defines drawing commands, whereas Imagick stores and exports the actual image.

Common Beginner Mistakes


MistakeCorrect Approach
Expecting a draw command to appear in an image without passing its ImagickDraw context to Imagick::drawImage().A drawing instruction or setting does not create a visible image until you render the drawing context with Imagick::drawImage().
Choosing Imagick::drawImage() without checking whether it provides the same result.ImagickDraw defines drawing commands, whereas Imagick stores and exports the actual image.

Key Takeaways


  • Draws a circle using its center and another point on the circumference.
  • A drawing instruction or setting does not create a visible image until you render the drawing context with Imagick::drawImage().
  • Coordinate values use pixels in the image canvas. Font availability and ImageMagick configuration can vary.

The examples demonstrate where ImagickDraw::circle fits within image drawing. Verify the relevant preconditions whenever you adapt the code to real data.

Share this resourceSend this page to someone who may find it useful.