Python3 Picture processing Avatar

Source: Internet
Author: User

I. Introduction:

Python3 picture processing avatar on the top right corner similar to QQ, the upper right corner unread information effect, in fact, no real effect, just simple practice.

1. Environment:

python3.5

Random module: Generating stochastic numbers

PIL module: Image processing module

Image: Loading pictures

Imagefont: Loading Fonts

Imagedraw: Creating a Picture Object

Note: The PIL module has been replaced with the Pillow module (document: http://pillow.readthedocs.org/en/latest/) in python3.x, and the module can be installed directly using the PIP3 install Pillow Use the From PIL import Image when importing.

  

2.:

Two. Code implementation:

 fromPILImportImage, Imagefont, ImagedrawImportRandommsgnum= Str ((Random.randint (1, 99))#Generate random numbersim= Image.open ('test.jpg')#Loading PicturesW, h = im.size#get picture width and heightWdraw = 0.8*w#define numeric coordinatesHdraw = 0.05*Hfron= Imagefont.truetype ('Xiaoxiangzi.ttf', 30)#font and size of loaded valuesDraw= Imagedraw.draw (IM)#Create an imageDraw.text (Wdraw, Hdraw), Msgnum, Font=fron, fill= (255, 33, 33))#Defining image Formats    #(Wdraw, Hdraw): coordinates    #msgnum: Random number    #Font : Custom font and size    #fill: Defines the color, can be the number format can also be directly specified in English such as: fill= "Red"Im.save ('Test2.png','PNG')#Save the generated image in the specified format,

  

Python3 picture processing avatar

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.