Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 56f30ef

Browse files
committed
Allow explicit zero width to hide outline
1 parent ef4a0b2 commit 56f30ef

File tree

7 files changed

+60
-12
lines changed

7 files changed

+60
-12
lines changed
427 Bytes
Loading
339 Bytes
Loading
403 Bytes
Loading
212 Bytes
Loading

Tests/test_imagedraw.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ def test_chord_width_fill(self):
214214
# Assert
215215
self.assert_image_similar(im, Image.open(expected), 1)
216216

217+
def test_chord_zero_width(self):
218+
# Arrange
219+
im = Image.new("RGB", (W, H))
220+
draw = ImageDraw.Draw(im)
221+
222+
# Act
223+
draw.chord(BBOX1, 10, 260, fill="red", outline="yellow", width=0)
224+
225+
# Assert
226+
with Image.open("Tests/images/imagedraw_chord_zero_width.png") as expected:
227+
self.assert_image_equal(im, expected)
228+
217229
def helper_ellipse(self, mode, bbox):
218230
# Arrange
219231
im = Image.new(mode, (W, H))
@@ -290,6 +302,18 @@ def test_ellipse_width_fill(self):
290302
# Assert
291303
self.assert_image_similar(im, Image.open(expected), 1)
292304

305+
def test_ellipse_zero_width(self):
306+
# Arrange
307+
im = Image.new("RGB", (W, H))
308+
draw = ImageDraw.Draw(im)
309+
310+
# Act
311+
draw.ellipse(BBOX1, fill="green", outline="blue", width=0)
312+
313+
# Assert
314+
with Image.open("Tests/images/imagedraw_ellipse_zero_width.png") as expected:
315+
self.assert_image_equal(im, expected)
316+
293317
def helper_line(self, points):
294318
# Arrange
295319
im = Image.new("RGB", (W, H))
@@ -392,6 +416,18 @@ def test_pieslice_width_fill(self):
392416
# Assert
393417
self.assert_image_similar(im, Image.open(expected), 1)
394418

419+
def test_pieslice_zero_width(self):
420+
# Arrange
421+
im = Image.new("RGB", (W, H))
422+
draw = ImageDraw.Draw(im)
423+
424+
# Act
425+
draw.pieslice(BBOX1, 10, 260, fill="white", outline="blue", width=0)
426+
427+
# Assert
428+
with Image.open("Tests/images/imagedraw_pieslice_zero_width.png") as expected:
429+
self.assert_image_equal(im, expected)
430+
395431
def helper_point(self, points):
396432
# Arrange
397433
im = Image.new("RGB", (W, H))
@@ -496,6 +532,18 @@ def test_rectangle_width_fill(self):
496532
# Assert
497533
self.assert_image_equal(im, Image.open(expected))
498534

535+
def test_rectangle_zero_width(self):
536+
# Arrange
537+
im = Image.new("RGB", (W, H))
538+
draw = ImageDraw.Draw(im)
539+
540+
# Act
541+
draw.rectangle(BBOX1, fill="blue", outline="green", width=0)
542+
543+
# Assert
544+
with Image.open("Tests/images/imagedraw_rectangle_zero_width.png") as expected:
545+
self.assert_image_equal(im, expected)
546+
499547
def test_rectangle_I16(self):
500548
# Arrange
501549
im = Image.new("I;16", (W, H))

docs/reference/ImageDraw.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Methods
154154
To paste pixel data into an image, use the
155155
:py:meth:`~PIL.Image.Image.paste` method on the image itself.
156156

157-
.. py:method:: PIL.ImageDraw.ImageDraw.chord(xy, start, end, fill=None, outline=None, width=0)
157+
.. py:method:: PIL.ImageDraw.ImageDraw.chord(xy, start, end, fill=None, outline=None, width=1)
158158
159159
Same as :py:meth:`~PIL.ImageDraw.ImageDraw.arc`, but connects the end points
160160
with a straight line.
@@ -168,7 +168,7 @@ Methods
168168

169169
.. versionadded:: 5.3.0
170170

171-
.. py:method:: PIL.ImageDraw.ImageDraw.ellipse(xy, fill=None, outline=None, width=0)
171+
.. py:method:: PIL.ImageDraw.ImageDraw.ellipse(xy, fill=None, outline=None, width=1)
172172
173173
Draws an ellipse inside the given bounding box.
174174

@@ -198,7 +198,7 @@ Methods
198198

199199
.. versionadded:: 5.3.0
200200

201-
.. py:method:: PIL.ImageDraw.ImageDraw.pieslice(xy, start, end, fill=None, outline=None, width=0)
201+
.. py:method:: PIL.ImageDraw.ImageDraw.pieslice(xy, start, end, fill=None, outline=None, width=1)
202202
203203
Same as arc, but also draws straight lines between the end points and the
204204
center of the bounding box.
@@ -236,7 +236,7 @@ Methods
236236
:param outline: Color to use for the outline.
237237
:param fill: Color to use for the fill.
238238

239-
.. py:method:: PIL.ImageDraw.ImageDraw.rectangle(xy, fill=None, outline=None, width=0)
239+
.. py:method:: PIL.ImageDraw.ImageDraw.rectangle(xy, fill=None, outline=None, width=1)
240240
241241
Draws a rectangle.
242242

src/PIL/ImageDraw.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,20 @@ def bitmap(self, xy, bitmap, fill=None):
134134
if ink is not None:
135135
self.draw.draw_bitmap(xy, bitmap.im, ink)
136136

137-
def chord(self, xy, start, end, fill=None, outline=None, width=0):
137+
def chord(self, xy, start, end, fill=None, outline=None, width=1):
138138
"""Draw a chord."""
139139
ink, fill = self._getink(outline, fill)
140140
if fill is not None:
141141
self.draw.draw_chord(xy, start, end, fill, 1)
142-
if ink is not None and ink != fill:
142+
if ink is not None and ink != fill and width != 0:
143143
self.draw.draw_chord(xy, start, end, ink, 0, width)
144144

145-
def ellipse(self, xy, fill=None, outline=None, width=0):
145+
def ellipse(self, xy, fill=None, outline=None, width=1):
146146
"""Draw an ellipse."""
147147
ink, fill = self._getink(outline, fill)
148148
if fill is not None:
149149
self.draw.draw_ellipse(xy, fill, 1)
150-
if ink is not None and ink != fill:
150+
if ink is not None and ink != fill and width != 0:
151151
self.draw.draw_ellipse(xy, ink, 0, width)
152152

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

222-
def pieslice(self, xy, start, end, fill=None, outline=None, width=0):
222+
def pieslice(self, xy, start, end, fill=None, outline=None, width=1):
223223
"""Draw a pieslice."""
224224
ink, fill = self._getink(outline, fill)
225225
if fill is not None:
226226
self.draw.draw_pieslice(xy, start, end, fill, 1)
227-
if ink is not None and ink != fill:
227+
if ink is not None and ink != fill and width != 0:
228228
self.draw.draw_pieslice(xy, start, end, ink, 0, width)
229229

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

244-
def rectangle(self, xy, fill=None, outline=None, width=0):
244+
def rectangle(self, xy, fill=None, outline=None, width=1):
245245
"""Draw a rectangle."""
246246
ink, fill = self._getink(outline, fill)
247247
if fill is not None:
248248
self.draw.draw_rectangle(xy, fill, 1)
249-
if ink is not None and ink != fill:
249+
if ink is not None and ink != fill and width != 0:
250250
self.draw.draw_rectangle(xy, ink, 0, width)
251251

252252
def _multiline_check(self, text):

0 commit comments

Comments
 (0)