Merge pull request #2922 from radarhere/fill_ink
Skip outline if the draw operation fills with the same colour
BIN
Tests/images/imagedraw_outline_chord_L.png
Normal file
After Width: | Height: | Size: 212 B |
BIN
Tests/images/imagedraw_outline_chord_RGB.png
Normal file
After Width: | Height: | Size: 259 B |
BIN
Tests/images/imagedraw_outline_ellipse_L.png
Normal file
After Width: | Height: | Size: 290 B |
BIN
Tests/images/imagedraw_outline_ellipse_RGB.png
Normal file
After Width: | Height: | Size: 378 B |
BIN
Tests/images/imagedraw_outline_pieslice_L.png
Normal file
After Width: | Height: | Size: 266 B |
BIN
Tests/images/imagedraw_outline_pieslice_RGB.png
Normal file
After Width: | Height: | Size: 340 B |
BIN
Tests/images/imagedraw_outline_polygon_L.png
Normal file
After Width: | Height: | Size: 309 B |
BIN
Tests/images/imagedraw_outline_polygon_RGB.png
Normal file
After Width: | Height: | Size: 393 B |
BIN
Tests/images/imagedraw_outline_rectangle_L.png
Normal file
After Width: | Height: | Size: 125 B |
BIN
Tests/images/imagedraw_outline_rectangle_RGB.png
Normal file
After Width: | Height: | Size: 212 B |
BIN
Tests/images/imagedraw_outline_shape_L.png
Normal file
After Width: | Height: | Size: 263 B |
BIN
Tests/images/imagedraw_outline_shape_RGB.png
Normal file
After Width: | Height: | Size: 316 B |
|
@ -576,6 +576,47 @@ class TestImageDraw(PillowTestCase):
|
||||||
draw.textsize("\n")
|
draw.textsize("\n")
|
||||||
draw.textsize("test\n")
|
draw.textsize("test\n")
|
||||||
|
|
||||||
|
def test_same_color_outline(self):
|
||||||
|
# Prepare shape
|
||||||
|
x0, y0 = 5, 5
|
||||||
|
x1, y1 = 5, 50
|
||||||
|
x2, y2 = 95, 50
|
||||||
|
x3, y3 = 95, 5
|
||||||
|
|
||||||
|
s = ImageDraw.Outline()
|
||||||
|
s.move(x0, y0)
|
||||||
|
s.curve(x1, y1, x2, y2, x3, y3)
|
||||||
|
s.line(x0, y0)
|
||||||
|
|
||||||
|
# Begin
|
||||||
|
for mode in ["RGB", "L"]:
|
||||||
|
for fill, outline in [
|
||||||
|
["red", None],
|
||||||
|
["red", "red"],
|
||||||
|
["red", "#f00"]
|
||||||
|
]:
|
||||||
|
for operation, args in {
|
||||||
|
'chord':[BBOX1, 0, 180],
|
||||||
|
'ellipse':[BBOX1],
|
||||||
|
'shape':[s],
|
||||||
|
'pieslice':[BBOX1, -90, 45],
|
||||||
|
'polygon':[[(18, 30), (85, 30), (60, 72)]],
|
||||||
|
'rectangle':[BBOX1]
|
||||||
|
}.items():
|
||||||
|
# Arrange
|
||||||
|
im = Image.new(mode, (W, H))
|
||||||
|
draw = ImageDraw.Draw(im)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
draw_method = getattr(draw, operation)
|
||||||
|
args += [fill, outline]
|
||||||
|
draw_method(*args)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
expected = ("Tests/images/imagedraw_outline"
|
||||||
|
"_{}_{}.png".format(operation, mode))
|
||||||
|
self.assert_image_similar(im, Image.open(expected), 1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -138,7 +138,7 @@ class ImageDraw(object):
|
||||||
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:
|
if ink is not None and ink != fill:
|
||||||
self.draw.draw_chord(xy, start, end, ink, 0)
|
self.draw.draw_chord(xy, start, end, ink, 0)
|
||||||
|
|
||||||
def ellipse(self, xy, fill=None, outline=None):
|
def ellipse(self, xy, fill=None, outline=None):
|
||||||
|
@ -146,7 +146,7 @@ class ImageDraw(object):
|
||||||
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:
|
if ink is not None and ink != fill:
|
||||||
self.draw.draw_ellipse(xy, ink, 0)
|
self.draw.draw_ellipse(xy, ink, 0)
|
||||||
|
|
||||||
def line(self, xy, fill=None, width=0):
|
def line(self, xy, fill=None, width=0):
|
||||||
|
@ -161,7 +161,7 @@ class ImageDraw(object):
|
||||||
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_outline(shape, fill, 1)
|
self.draw.draw_outline(shape, fill, 1)
|
||||||
if ink is not None:
|
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):
|
def pieslice(self, xy, start, end, fill=None, outline=None):
|
||||||
|
@ -169,7 +169,7 @@ class ImageDraw(object):
|
||||||
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:
|
if ink is not None and ink != fill:
|
||||||
self.draw.draw_pieslice(xy, start, end, ink, 0)
|
self.draw.draw_pieslice(xy, start, end, ink, 0)
|
||||||
|
|
||||||
def point(self, xy, fill=None):
|
def point(self, xy, fill=None):
|
||||||
|
@ -183,7 +183,7 @@ class ImageDraw(object):
|
||||||
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_polygon(xy, fill, 1)
|
self.draw.draw_polygon(xy, fill, 1)
|
||||||
if ink is not None:
|
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):
|
def rectangle(self, xy, fill=None, outline=None):
|
||||||
|
@ -191,7 +191,7 @@ class ImageDraw(object):
|
||||||
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:
|
if ink is not None and ink != fill:
|
||||||
self.draw.draw_rectangle(xy, ink, 0)
|
self.draw.draw_rectangle(xy, ink, 0)
|
||||||
|
|
||||||
def _multiline_check(self, text):
|
def _multiline_check(self, text):
|
||||||
|
|