[Image-SIG] some bug in PIL, with test case
Alain Spineux
aspineux at gmail.com
Sun Feb 11 23:30:34 CET 2007
Hello
I used PIL for the first time and found some bugs.
The code and description follow.
The main problem is that drawing a line from A to B dont get the same result
as from B to A!
And because of this (I thing) the color of a polygon overflow it's outline.
And last i found the size of a rotated image unpredictable!
The error is only of one 1 pixel, but this is enough to have to image
cover another or have a blank between them.
Best regards
Alain
Here is the code
def pil_bugs():
imgs=[]
# here the color of the polygone overflow the outline !
polygon=[(82, 39), (81, 8), (76, 0), (42, 0), (37, 7), (47, 39)]
img=Image.new('RGB', (100, 100), (255, 255, 255))
draw=ImageDraw.Draw(img)
draw.polygon(polygon, fill=(255,128,128), outline=(0,0,0))
del draw
imgs.append(img)
# here I draw multiple line with different gradient
# first from "center" to outside
# and second from outside to inside
# the second line don't match exactly the first one !
img=Image.new('RGB', (200, 200), (255, 255, 255))
w, h=img.size
cx, cy=w/2, h/2
pts=[ (80,0), (80,20), (80,40), (80, 60), (80,80) ]
draw=ImageDraw.Draw(img)
for x, y in pts:
draw.line((cx, cy, cx+x, cy+y), (0,0,0))
draw.line((cx, cy, cx+y, cy+x), (0,0,0))
draw.line((cx, cy, cx-x, cy+y), (0,0,0))
draw.line((cx, cy, cx-y, cy+x), (0,0,0))
draw.line((cx, cy, cx-x, cy-y), (0,0,0))
draw.line((cx, cy, cx-y, cy-x), (0,0,0))
draw.line((cx, cy, cx+x, cy-y), (0,0,0))
draw.line((cx, cy, cx+y, cy-x), (0,0,0))
draw.line((cx+x, cy+y, cx, cy), (255,0,0))
draw.line((cx+y, cy+x, cx, cy), (255,0,0))
draw.line((cx-x, cy+y, cx, cy), (255,0,0))
draw.line((cx-y, cy+x, cx, cy), (255,0,0))
draw.line((cx-x, cy-y, cx, cy), (255,0,0))
draw.line((cx-y, cy-x, cx, cy), (255,0,0))
draw.line((cx+x, cy-y, cx, cy), (255,0,0))
draw.line((cx+y, cy-x, cx, cy), (255,0,0))
del draw
imgs.append(img)
# this test compare the logical size of a rotated image with the real one
img=Image.new('RGB', (100, 27), (255, 255, 255))
w, h=img.size
for alpha in range(0, 90, 1):
riw, rih=img.rotate(alpha, Image.BICUBIC, True).size
u=h*math.sin(math.radians(alpha))+w*math.cos(math.radians(alpha))
v=w*math.sin(math.radians(alpha))+h*math.cos(math.radians(alpha))
rfw, rfh=int(math.floor(u)), int(math.floor(v))
rcw, rch=int(math.ceil(u)), int(math.ceil(v))
print '%3d: %3dx%3d %5.1fx%5.1f floor %-2d %-2d ceil %-2d
%-2d' % ( alpha, riw, rih, u, v, riw-rfw , rih-rfh, riw-rcw, rih-rch)
# this is not a bug, but why to mix size and vertices ?
# 99!=100 this could disturb the user that must make +1 or -1
img=Image.new('RGB', (100, 100), (255, 255, 255))
img=img.transform(img.size, Image.MESH, [((0, 0, 100, 100),
(0,0,0,99,99,99,99,0))], Image.BICUBIC)
# imgs.append(img)
return imgs
--
Alain Spineux
aspineux gmail com
May the sources be with you
More information about the Image-SIG
mailing list