21 |
21 |
22 __docformat__ = "restructuredtext en" |
22 __docformat__ = "restructuredtext en" |
23 |
23 |
24 from random import randint, choice |
24 from random import randint, choice |
25 from io import BytesIO |
25 from io import BytesIO |
|
26 |
|
27 from six.moves import range |
26 |
28 |
27 from PIL import Image, ImageFont, ImageDraw, ImageFilter |
29 from PIL import Image, ImageFont, ImageDraw, ImageFilter |
28 |
30 |
29 |
31 |
30 from time import time |
32 from time import time |
49 # create a new image slightly larger that the text |
51 # create a new image slightly larger that the text |
50 img = Image.new('RGB', (dim[0]+5, dim[1]+5), bgcolor) |
52 img = Image.new('RGB', (dim[0]+5, dim[1]+5), bgcolor) |
51 draw = ImageDraw.Draw(img) |
53 draw = ImageDraw.Draw(img) |
52 # draw 100 random colored boxes on the background |
54 # draw 100 random colored boxes on the background |
53 x, y = img.size |
55 x, y = img.size |
54 for num in xrange(100): |
56 for num in range(100): |
55 draw.rectangle((randint(0, x), randint(0, y), |
57 draw.rectangle((randint(0, x), randint(0, y), |
56 randint(0, x), randint(0, y)), |
58 randint(0, x), randint(0, y)), |
57 fill=randint(0, 0xffffff)) |
59 fill=randint(0, 0xffffff)) |
58 # add the text to the image |
60 # add the text to the image |
59 draw.text((3, 3), text, font=font, fill=fgcolor) |
61 draw.text((3, 3), text, font=font, fill=fgcolor) |