Skip to content

Conversation

@radarhere
Copy link
Member

Resolves #367

#6625 documented that ImageDraw's rectangle() included the endpoints. This continues that clarification of the documentation for line() and polygon().

As a demonstration, see the following code comparing the three functions.

from PIL import Image, ImageDraw

img = Image.new('RGB', (10, 10), (255, 255, 255))
draw = ImageDraw.Draw(img, 'RGBA')
draw.polygon([(2,2), (2, 8), (8,8), (8, 2)], fill=(0, 255, 0, 127))
draw.rectangle([(2,2), (8,8)], fill=(255, 0, 0, 127))
draw.line([(2,2), (8,8)], fill=(0, 0, 0, 255))

img.resize((200, 200), Image.NONE).save("out.png")

.. py:method:: ImageDraw.line(xy, fill=None, width=0, joint=None)
Draws a line between the coordinates in the ``xy`` list.
The coordinate pixels are included in the drawn line.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a bit clearer?

Suggested change
The coordinate pixels are included in the drawn line.
The endpoint coordinate pixels are included in the drawn line.

Or simply?

Suggested change
The coordinate pixels are included in the drawn line.
The endpoint pixels are included in the drawn line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to update it with any wording that you think is clearer, but both line() and polygon() accept a series of coordinates. I wonder if saying 'endpoint' implies it is only the first and last of those coordinates that are included?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good point. Not sure now! Let's stick with the original :)

The polygon outline consists of straight lines between the given
coordinates, plus a straight line between the last and the first
coordinate.
coordinate. The coordinate pixels are included in the drawn polygon.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
coordinate. The coordinate pixels are included in the drawn polygon.
coordinate. The endpoint coordinate pixels are included in the drawn polygon.
Suggested change
coordinate. The coordinate pixels are included in the drawn polygon.
coordinate. The endpoint pixels are included in the drawn polygon.

@hugovk hugovk merged commit 0efd72d into python-pillow:main May 12, 2023
@radarhere radarhere deleted the imagedraw branch May 13, 2023 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vertical lines drawn with draw.line have one extra width pixel

2 participants