#Coding=utf-8 fromPILImportImage, Imagedraw, Imagefont, ImageFilterImportRandom#Random Letters:defRndchar ():returnChr (Random.randint (65, 90))#random color 1:defRndcolor ():return(Random.randint (255), Random.randint (255), Random.randint (64, 255))#Random color 2:defRndColor2 ():return(Random.randint (0,1), random.randint (0,1), Random.randint (0,1))#x:width = 60 * 4Height= 60Image= Image.new ('RGB', (width, height), (255, 255, 255))#To Create a Font object:Font = Imagefont.truetype ('C:\\windows\\fonts\\arial.ttf', 36)#To create a draw object:Draw =Imagedraw.draw (image)#fill each pixel: forXinchRange (width): forYinchRange (height): Draw.point ((x, y), fill=Rndcolor ())#Output Text: forTinchRange (4): Draw.text ((* t + ten, Rndchar (), Font=font, fill=RndColor2 ())#Blur:Image =Image.filter (Imagefilter.blur) Image.Save ('code.jpg','JPEG')
Reprinted from: Http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/ 0014320027235877860c87af5544f25a8deeb55141d60c5000
Python generates a simple verification code