Python generates a simple verification code

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.