Pillow: Is the ImageDraw.Draw.rectangle documentation wrong?

Created on 19 Jan 2019  路  4Comments  路  Source: python-pillow/Pillow

What did you do?

I read the documentation on PIL.ImageDraw.Draw.rectangle, which states: The second point is just outside the drawn rectangle. (source: https://pillow.readthedocs.io/en/3.0.x/reference/ImageDraw.html )

Then, I tried out drawing a rectangle of size (0, 0, 200, 20)

What did you expect to happen?

A rectangle that starts at pixel 0 and ends before pixel 200, that is 0-199, with 200 pixels width, with 20 pixels height

What actually happened?

A 201x21 px rectangle, as if the ending point was just inside the rectangle (instead of outside as the docs say)

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 18.04 (inside docker, host is fedora 29)
  • Python: 3.6.7
  • Pillow: 5.4.7 (PIL.PILLOW_VERSION)
# (don't have a minimal example right now)
Duplicate

Most helpful comment

I will note that there is no Pillow 5.4.7.

Here is code to demonstrate your situation -

from PIL import Image, ImageDraw
im = Image.new("RGB", (300, 300), "#fff")
d = ImageDraw.Draw(im)
d.rectangle((0, 0, 200, 20), "#000")
im.save("out.png")

All 4 comments

I will note that there is no Pillow 5.4.7.

Here is code to demonstrate your situation -

from PIL import Image, ImageDraw
im = Image.new("RGB", (300, 300), "#fff")
d = ImageDraw.Draw(im)
d.rectangle((0, 0, 200, 20), "#000")
im.save("out.png")

@radarhere that's what PIL.PILLOW_VERSION was set to for some reason :woman_shrugging: I don't know

And even better example - there is no need to count pixels, just note that black line appeared + show function.

from PIL import Image, ImageDraw
im = Image.new("RGB", (300, 30), "#fff")
d = ImageDraw.Draw(im)
d.rectangle((10, 10, 290, 10), "#000")
im.save("out.png")
im.show()

out

Feel free to comment if you think otherwise, but I'm closing this is as a duplicate of #1668.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nomarek picture nomarek  路  3Comments

maxhumber picture maxhumber  路  3Comments

damianmoore picture damianmoore  路  4Comments

thinrhino picture thinrhino  路  3Comments

boskicthebrain picture boskicthebrain  路  4Comments