forked from Show-Me-the-Code/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateIdentifyingCode.py
More file actions
33 lines (24 loc) · 917 Bytes
/
CreateIdentifyingCode.py
File metadata and controls
33 lines (24 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-
__author__ = 'PatchLion'
from PIL import Image, ImageDraw, ImageFont, ImageFilter
import random
def randChar():
#65-90 A-Z
return chr(random.randint(65, 90))
def randColor():
return (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
def createIdentifyingCode(size, charcount=4):
width=size*charcount
height=size
img = Image.new('RGB', (width, height), (255, 255, 255))
draw = ImageDraw.Draw(img)
for x in range(width):
for y in range(height):
draw.point((x, y), fill=randColor())
font = ImageFont.truetype("../0000/Varela-Regular.otf", size=size)
#draw.text((0, 0), randChar(), fill=randColor())
for i in range(charcount):
draw.text((i*size + 10, -10), randChar(), fill=randColor(), font=font)
img = img.filter(ImageFilter.BLUR)
img.save('ic.jpg', 'jpeg')
createIdentifyingCode(60)