代码如下:
from PIL import Image,ImageDraw,ImageFont,ImageFilter
import random
def rndChar(): # 随机生成书记转化成ASCLL码
return chr(random.randint(65,90))
def rndColor(m,n) # 随机生成颜色:
return tuple(random.randint(m,n)for i in range(3))
image=Image.new('RGB',(240,60),(255,255,255)) # 白色背景图
font=ImageFont.truetype('arial.ttf',36) # 字体
draw=ImageDraw.Draw(image)
for x in range(240): # 绘制随机颜色点
for y in range(60):
draw.point((x,y),fill=rndColor(64,255))
for t in range(5): # 输出文字
draw.text((40*t+20,10),rndChar(),font=font,fill=rndColor(32,128))
image=image.filter(ImageFilter.BLUR) # 调用滤镜, 实现模糊化
image.show()
效果图: