Generate their own exclusive phone New Year wallpaper with Python
effect:
To
Ready to work:
Python need to use third-party image processing libraries: PIL (Python Image Library).
- python 2.X: PIL
- python 3.X : pillow
. 1 __author__ = ' MaZW '
2 # - * - Coding: UTF-. 8 - * -
. 3 from the PIL Import Image, ImageDraw, ImageFont
. 4 A = ' Wang Wang '
. 5 font = ImageFont.truetype ( ' simhei.ttf ' , 100) # define text, bold
. 6 IMG = Image.open ( ' underlay .jpg ' )
. 7 Draw = ImageDraw.Draw (IMG) # new canvas painting objects
. 8
. 9 draw.text ((200, 700), A, (0, 0,0), font = font)
10 #The new coordinates of the object (200, 700) drawn at the beginning of black text
. 11 img.show ()
12 is img.save ( ' wallpaper .jpg ' )
summary:
PIL learned in core classes Image:
-
save (filename, format) (save the image in a specified format)
-
open (filename, mode) (an image open).
-
paste (region, box, mask) (one image to another image paste)