Without further ado, let’s go directly to the code
import itchat import math import PIL.Image as Image import os itchat.auto_login() friends = itchat.get_friends(update=True)[0:] user = friends[0]["UserName"] num = 0for i in friends: img = itchat.get_head_img(userName=i["UserName"]) fileImage = open('文件夹' + "/" + str(num) + ".jpg",'wb') fileImage.write(img) fileImage.close() num += 1ls = os.listdir('文件夹') each_size = int(math.sqrt(float(640*640)/len(ls))) lines = int(640/each_size) image = Image.new('RGBA', (640, 640))x = 0y = 0for i in range(0,len(ls)+1):try: img = Image.open('文件夹' + "/" + str(i) + ".jpg") except IOError:print("Error")else: img = img.resize((each_size, each_size), Image.ANTIALIAS) image.paste(img, (x * each_size, y * each_size))x += 1if x == lines:x = 0y += 1 image.save('文件夹' + "/" + "all.jpg") itchat.send_image('文件夹' + "/" + "all.jpg", 'filehelper')
pip install itchat pip install pillow
If the pip installation option is not ticked when installing python, install pip first.
Installation of Python and pip
A login QR code will appear during the running of the code, scan it with WeChat , you can see the progress of the processing. After a while, your WeChat file transfer assistant will receive the spliced avatar picture.
If you encounter any problems during the learning process or want to obtain learning resources, you are welcome to join the learning exchange group
The above is the detailed content of Share how Python implements avatar splicing technology/. For more information, please follow other related articles on the PHP Chinese website!