Merge pull request #4334 from radarhere/outline_width

Allow explicit zero width to hide outline
This commit is contained in:
Hugo van Kemenade 2020-02-15 14:30:12 +02:00 committed by GitHub
commit 0e993c4740
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 60 additions and 12 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 403 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

View File

@ -214,6 +214,18 @@ class TestImageDraw(PillowTestCase):
# Assert # Assert
assert_image_similar(im, Image.open(expected), 1) 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): def helper_ellipse(self, mode, bbox):
# Arrange # Arrange
im = Image.new(mode, (W, H)) im = Image.new(mode, (W, H))
@ -302,6 +314,18 @@ class TestImageDraw(PillowTestCase):
# Assert # Assert
assert_image_similar(im, Image.open(expected), 1) 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): def helper_line(self, points):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
@ -402,6 +426,18 @@ class TestImageDraw(PillowTestCase):
# Assert # Assert
assert_image_similar(im, Image.open(expected), 1) 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): def helper_point(self, points):
# Arrange # Arrange
im = Image.new("RGB", (W, H)) im = Image.new("RGB", (W, H))
@ -506,6 +542,18 @@ class TestImageDraw(PillowTestCase):
# Assert # Assert
assert_image_equal(im, Image.open(expected)) 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): def test_rectangle_I16(self):
# Arrange # Arrange
im = Image.new("I;16", (W, H)) im = Image.new("I;16", (W, H))

View File

@ -154,7 +154,7 @@ Methods
To paste pixel data into an image, use the To paste pixel data into an image, use the
:py:meth:`~PIL.Image.Image.paste` method on the image itself. :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 Same as :py:meth:`~PIL.ImageDraw.ImageDraw.arc`, but connects the end points
with a straight line. with a straight line.
@ -168,7 +168,7 @@ Methods
.. versionadded:: 5.3.0 .. 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. Draws an ellipse inside the given bounding box.
@ -198,7 +198,7 @@ Methods
.. versionadded:: 5.3.0 .. 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 Same as arc, but also draws straight lines between the end points and the
center of the bounding box. center of the bounding box.
@ -236,7 +236,7 @@ Methods
:param outline: Color to use for the outline. :param outline: Color to use for the outline.
:param fill: Color to use for the fill. :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. Draws a rectangle.

View File

@ -134,20 +134,20 @@ class ImageDraw:
if ink is not None: if ink is not None:
self.draw.draw_bitmap(xy, bitmap.im, ink) 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.""" """Draw a chord."""
ink, fill = self._getink(outline, fill) ink, fill = self._getink(outline, fill)
if fill is not None: if fill is not None:
self.draw.draw_chord(xy, start, end, fill, 1) 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) 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.""" """Draw an ellipse."""
ink, fill = self._getink(outline, fill) ink, fill = self._getink(outline, fill)
if fill is not None: if fill is not None:
self.draw.draw_ellipse(xy, fill, 1) 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) self.draw.draw_ellipse(xy, ink, 0, width)
def line(self, xy, fill=None, width=0, joint=None): def line(self, xy, fill=None, width=0, joint=None):
@ -219,12 +219,12 @@ class ImageDraw:
if ink is not None and ink != fill: if ink is not None and ink != fill:
self.draw.draw_outline(shape, ink, 0) 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.""" """Draw a pieslice."""
ink, fill = self._getink(outline, fill) ink, fill = self._getink(outline, fill)
if fill is not None: if fill is not None:
self.draw.draw_pieslice(xy, start, end, fill, 1) 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) self.draw.draw_pieslice(xy, start, end, ink, 0, width)
def point(self, xy, fill=None): def point(self, xy, fill=None):
@ -241,12 +241,12 @@ class ImageDraw:
if ink is not None and ink != fill: if ink is not None and ink != fill:
self.draw.draw_polygon(xy, ink, 0) 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.""" """Draw a rectangle."""
ink, fill = self._getink(outline, fill) ink, fill = self._getink(outline, fill)
if fill is not None: if fill is not None:
self.draw.draw_rectangle(xy, fill, 1) 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) self.draw.draw_rectangle(xy, ink, 0, width)
def _multiline_check(self, text): def _multiline_check(self, text):