Python generates a verification code

Source: Internet
Author: User

The Windows operating system font files are stored in the following locations:

C:\Windows\Fonts

From PIL import image,imagefilter,imagedraw,imagefontimport random# random Letter Def Rndchar ():    return Chr (Random.randint ( 65,90)) #随机颜色1:d EF rndcolor ():    return (Random.randint (64,255), Random.randint (64,255), Random.randint (64,255)) # Random color 2:def RndColor2 ():    return (Random.randint (32,127), Random.randint (32,127), Random.randint (32,127)) #240 * 60: width = 60*4height = 60image = Image.new (' RGB ', (width,height), (255,255,255)) #创建Font对象: Font = imagefont.truetype (' \ c \ Windows\fonts\arial.ttf ', #创建Draw对象:d raw = Imagedraw.draw (image) #填充每个像素: for x in range (width): A for    y in range ( Height):        draw.point ((x, y), fill = Rndcolor ()) #输出文字: for T in range (4):    Draw.text ((60*t+10,10), Rndchar (), font= Font,fill=rndcolor2 ()) #模糊: image = Image.filter (imagefilter.blur) image.save (' f:/code.jpg ', ' jpeg ')

Python generates a 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.