forked from Show-Me-the-Code/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice10.py
More file actions
25 lines (20 loc) · 807 Bytes
/
practice10.py
File metadata and controls
25 lines (20 loc) · 807 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
# -*- coding:utf-8 -*-
import string
import random
from PIL import Image,ImageDraw,ImageFont,ImageFilter
def numgenerator(size=4, chars=string.ascii_uppercase + string.digits + string.ascii_lowercase):
return ''.join(random.choice(chars) for _ in range(size))
def getcolor():
return (random.randint(0,255),random.randint(0,255),random.randint(0,255))
def getfont():
font = ImageFont.truetype('Arial.ttf',random.randint(50,65))
return font
check = numgenerator()
imageFile = "./bacdgroud.jpg"
img = Image.open(imageFile)
draw = ImageDraw.Draw(img)
for i in range(4):
draw.text((72*i+random.randint(15,20), random.randint(5,10)),check[i],getcolor(),font=getfont())
draw = ImageDraw.Draw(img)
image = img.filter(ImageFilter.BLUR)
image.save("./test1.jpg")