Haha, let's take a look at the results after running (below)
Description: (expressions and text can be customized)
1. First download a python pygame package
①Go to the command prompt
win + R
② After entering the command prompt, enter pip install pygame directly and press Enter
Download it after a while
2. Create a new py file to start writing code
①Introduce the required runtime package first
import sys from email.header import UTF8 reload(sys) sys.setdefaultencoding("gbk") import them import pygame from pygame.locals import *
② Prepare materials and import (my materials)
Use code to reference and set synthetic properties
img = Image.open("../img/head.jpg") #250*250 jgz = Image.open("../img/face.jpg") #101*113 img.paste(jgz, (73, 47)) #left and right, up and down
③Set the text we need to synthesize
draw = ImageDraw.Draw(img) ttfront = ImageFont.truetype('simhei.ttf', 24) #Set the font and font size draw.text((32, 190), "You are so arrogant\n I can't afford it".decode('utf8'), #Customize the printed text and the position of the text fill=(0, 0, 0), #text color font=ttfront) #font
④ Last save
img.save("_biaoq.jpg")
3. Here is the complete code:
#-*- coding:utf-8 -*- import sys from email.header import UTF8 reload(sys) sys.setdefaultencoding("gbk") import them import pygame from pygame.locals import * pygame.init() from PIL import Image, ImageDraw, ImageFont img = Image.open("../img/head.jpg") #250*250 jgz = Image.open("../img/face.jpg") #101*113 img.paste(jgz, (73, 47)) #left and right, up and down #img.show() draw = ImageDraw.Draw(img) ttfront = ImageFont.truetype('simhei.ttf', 24) draw.text((32, 190), "You are so arrogant\n I can't afford it".decode('utf8'), fill=(0, 0, 0), font=ttfront) #img.show() img.save("_biaoq.jpg") print('The expression package is synthesized, please check on the above')