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