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

Allow explicit zero width to hide outline #4334

Merged
merged 1 commit into from Feb 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added Tests/images/imagedraw_chord_zero_width.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/imagedraw_ellipse_zero_width.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/imagedraw_pieslice_zero_width.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/imagedraw_rectangle_zero_width.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions Tests/test_imagedraw.py
Expand Up @@ -214,6 +214,18 @@ def test_chord_width_fill(self):
# Assert
self.assert_image_similar(im, Image.open(expected), 1)

def test_chord_zero_width(self):
# Arrange
im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im)

# Act
draw.chord(BBOX1, 10, 260, fill="red", outline="yellow", width=0)

# Assert
with Image.open("Tests/images/imagedraw_chord_zero_width.png") as expected:
self.assert_image_equal(im, expected)

def helper_ellipse(self, mode, bbox):
# Arrange
im = Image.new(mode, (W, H))
Expand Down Expand Up @@ -290,6 +302,18 @@ def test_ellipse_width_fill(self):
# Assert
self.assert_image_similar(im, Image.open(expected), 1)

def test_ellipse_zero_width(self):
# Arrange
im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im)

# Act
draw.ellipse(BBOX1, fill="green", outline="blue", width=0)

# Assert
with Image.open("Tests/images/imagedraw_ellipse_zero_width.png") as expected:
self.assert_image_equal(im, expected)

def helper_line(self, points):
# Arrange
im = Image.new("RGB", (W, H))
Expand Down Expand Up @@ -392,6 +416,18 @@ def test_pieslice_width_fill(self):
# Assert
self.assert_image_similar(im, Image.open(expected), 1)

def test_pieslice_zero_width(self):
# Arrange
im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im)

# Act
draw.pieslice(BBOX1, 10, 260, fill="white", outline="blue", width=0)

# Assert
with Image.open("Tests/images/imagedraw_pieslice_zero_width.png") as expected:
self.assert_image_equal(im, expected)

def helper_point(self, points):
# Arrange
im = Image.new("RGB", (W, H))
Expand Down Expand Up @@ -496,6 +532,18 @@ def test_rectangle_width_fill(self):
# Assert
self.assert_image_equal(im, Image.open(expected))

def test_rectangle_zero_width(self):
# Arrange
im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im)

# Act
draw.rectangle(BBOX1, fill="blue", outline="green", width=0)

# Assert
with Image.open("Tests/images/imagedraw_rectangle_zero_width.png") as expected:
self.assert_image_equal(im, expected)

def test_rectangle_I16(self):
# Arrange
im = Image.new("I;16", (W, H))
Expand Down
8 changes: 4 additions & 4 deletions docs/reference/ImageDraw.rst
Expand Up @@ -154,7 +154,7 @@ Methods
To paste pixel data into an image, use the
:py:meth:`~PIL.Image.Image.paste` method on the image itself.

.. py:method:: PIL.ImageDraw.ImageDraw.chord(xy, start, end, fill=None, outline=None, width=0)
.. py:method:: PIL.ImageDraw.ImageDraw.chord(xy, start, end, fill=None, outline=None, width=1)

Same as :py:meth:`~PIL.ImageDraw.ImageDraw.arc`, but connects the end points
with a straight line.
Expand All @@ -168,7 +168,7 @@ Methods

.. versionadded:: 5.3.0

.. py:method:: PIL.ImageDraw.ImageDraw.ellipse(xy, fill=None, outline=None, width=0)
.. py:method:: PIL.ImageDraw.ImageDraw.ellipse(xy, fill=None, outline=None, width=1)

Draws an ellipse inside the given bounding box.

Expand Down Expand Up @@ -198,7 +198,7 @@ Methods

.. versionadded:: 5.3.0

.. py:method:: PIL.ImageDraw.ImageDraw.pieslice(xy, start, end, fill=None, outline=None, width=0)
.. py:method:: PIL.ImageDraw.ImageDraw.pieslice(xy, start, end, fill=None, outline=None, width=1)

Same as arc, but also draws straight lines between the end points and the
center of the bounding box.
Expand Down Expand Up @@ -236,7 +236,7 @@ Methods
:param outline: Color to use for the outline.
:param fill: Color to use for the fill.

.. py:method:: PIL.ImageDraw.ImageDraw.rectangle(xy, fill=None, outline=None, width=0)
.. py:method:: PIL.ImageDraw.ImageDraw.rectangle(xy, fill=None, outline=None, width=1)

Draws a rectangle.

Expand Down
16 changes: 8 additions & 8 deletions src/PIL/ImageDraw.py
Expand Up @@ -134,20 +134,20 @@ def bitmap(self, xy, bitmap, fill=None):
if ink is not None:
self.draw.draw_bitmap(xy, bitmap.im, ink)

def chord(self, xy, start, end, fill=None, outline=None, width=0):
def chord(self, xy, start, end, fill=None, outline=None, width=1):
"""Draw a chord."""
ink, fill = self._getink(outline, fill)
if fill is not None:
self.draw.draw_chord(xy, start, end, fill, 1)
if ink is not None and ink != fill:
if ink is not None and ink != fill and width != 0:
self.draw.draw_chord(xy, start, end, ink, 0, width)

def ellipse(self, xy, fill=None, outline=None, width=0):
def ellipse(self, xy, fill=None, outline=None, width=1):
"""Draw an ellipse."""
ink, fill = self._getink(outline, fill)
if fill is not None:
self.draw.draw_ellipse(xy, fill, 1)
if ink is not None and ink != fill:
if ink is not None and ink != fill and width != 0:
self.draw.draw_ellipse(xy, ink, 0, width)

def line(self, xy, fill=None, width=0, joint=None):
Expand Down Expand Up @@ -219,12 +219,12 @@ def shape(self, shape, fill=None, outline=None):
if ink is not None and ink != fill:
self.draw.draw_outline(shape, ink, 0)

def pieslice(self, xy, start, end, fill=None, outline=None, width=0):
def pieslice(self, xy, start, end, fill=None, outline=None, width=1):
"""Draw a pieslice."""
ink, fill = self._getink(outline, fill)
if fill is not None:
self.draw.draw_pieslice(xy, start, end, fill, 1)
if ink is not None and ink != fill:
if ink is not None and ink != fill and width != 0:
self.draw.draw_pieslice(xy, start, end, ink, 0, width)

def point(self, xy, fill=None):
Expand All @@ -241,12 +241,12 @@ def polygon(self, xy, fill=None, outline=None):
if ink is not None and ink != fill:
self.draw.draw_polygon(xy, ink, 0)

def rectangle(self, xy, fill=None, outline=None, width=0):
def rectangle(self, xy, fill=None, outline=None, width=1):
"""Draw a rectangle."""
ink, fill = self._getink(outline, fill)
if fill is not None:
self.draw.draw_rectangle(xy, fill, 1)
if ink is not None and ink != fill:
if ink is not None and ink != fill and width != 0:
self.draw.draw_rectangle(xy, ink, 0, width)

def _multiline_check(self, text):
Expand Down