#coding:utf-8
import random
from PIL import Image, ImageDraw, ImageFont, ImageFilter
#Image 负责处理图片
#ImageDraw 负责处理画笔
#imageFilter 负责处理滤镜
#定义一张图片
if __name__ == "__main__":
print "-------"
img = Image.new("RGB", (150,50),(255,255,255))
draw = ImageDraw.Draw(img)
#划线
for i in range (random.randint(1,10)):
draw.line(
[
( random.randint(1,150), random.randint(1,150) ),
( random.randint(1,150), random.randint(1,150) ),],
fill=(0,0,0)
)
#画点
for i in range (random.randint(1,1000)):
draw.point(
[ ( random.randint(1,150), random.randint(1,150) )],
fill=(255,0,0)
)
#front
fontList = list("abcdefghijklmnopqrstuvwsyz1234567890")
c_chars = " ".join(random.sample(fontList,5))
font = ImageFont.truetype("simsun.ttc",26)
draw.text((10,10),c_chars, font = font, fill="green")
#扭曲参数
param = [1-float(random.randint(1,2))/100,
0,
0,
0,
1-float(random.randint(1,2))/100,
float(random.randint(1,2))/500,
0.001,
float(random.randint(1,2)/100)
]
#扭曲
img = img.transform((150,50), Image.PERSPECTIVE, param)
#滤镜
img = img.filter(ImageFilter.EDGE_ENHANCE_MORE)
img.show()