Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ImageDraw circle() #8085

Merged
merged 12 commits into from
May 28, 2024
Merged
13 changes: 13 additions & 0 deletions docs/reference/ImageDraw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,19 @@ Methods

.. versionadded:: 5.3.0

.. py:method:: ImageDraw.circle(xy, radius, fill=None, outline=None, width=1)

Draws a circle given the center coordinates and a radius.
void4 marked this conversation as resolved.
Show resolved Hide resolved

:param xy: One point to define the circle center. Sequence:
``[x, y]``
:param radius: Radius of the circle
:param outline: Color to use for the outline.
:param fill: Color to use for the fill.
:param width: The line width, in pixels.

.. versionadded:: ?.?.?
void4 marked this conversation as resolved.
Show resolved Hide resolved

.. py:method:: ImageDraw.line(xy, fill=None, width=0, joint=None)

Draws a line between the coordinates in the ``xy`` list.
Expand Down
9 changes: 9 additions & 0 deletions src/PIL/ImageDraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@
if ink is not None and ink != fill and width != 0:
self.draw.draw_ellipse(xy, ink, 0, width)

def circle(self, xy: Coords, radius, fill=None, outline=None, width=1) -> None:
void4 marked this conversation as resolved.
Show resolved Hide resolved
"""Draw a circle given center coordinates and a radius."""
ink, fill = self._getink(outline, fill)
ellipse_xy = (xy[0] - radius, xy[1] - radius, xy[0] + radius, xy[1] + radius)
if fill is not None:
self.draw.draw_ellipse(ellipse_xy, fill, 1)
if ink is not None and ink != fill and width != 0:
self.draw.draw_ellipse(ellipse_xy, ink, 0, width)

Check warning on line 191 in src/PIL/ImageDraw.py

View check run for this annotation

Codecov / codecov/patch

src/PIL/ImageDraw.py#L186-L191

Added lines #L186 - L191 were not covered by tests
void4 marked this conversation as resolved.
Show resolved Hide resolved

def line(self, xy: Coords, fill=None, width=0, joint=None) -> None:
"""Draw a line, or a connected sequence of line segments."""
ink = self._getink(fill)[0]
Expand Down
Loading