SoFunction
Updated on 2024-11-16

Python implementation of the full avatar of friends stitching example (recommended)

WeChat Friends Full Avatar

Without further ado, let's get to the code

import itchat
import math
import  as Image
import os

itchat.auto_login()
friends = itchat.get_friends(update=True)[0:]
user = friends[0]["UserName"]

num = 0
for i in friends:
 img = itchat.get_head_img(userName=i["UserName"])
 fileImage = open('Folder' + "/" + str(num) + ".jpg",'wb')
 (img)
 ()
 num += 1

ls = ('Folder')
each_size = int((float(640*640)/len(ls)))
lines = int(640/each_size)
image = ('RGBA', (640, 640))
x = 0
y = 0
for i in range(0,len(ls)+1):
 try:
  img = ('Folder' + "/" + str(i) + ".jpg")
 except IOError:
  print("Error")
 else:
  img = ((each_size, each_size), )
  (img, (x * each_size, y * each_size))
  x += 1
  if x == lines:
   x = 0
   y += 1
('Folder' + "/" + "")
itchat.send_image('Folder' + "/" + "", 'filehelper')

Two libraries need to be installed for the code to run

pip install itchat
pip install pillow

If the pip install option is not ticked when installing python , install pip first.

Python and pip installation

itchat official introduction

Login QR code will appear during the code running, scan it with WeChat and you can see the progress of processing. After a while your WeChat file transfer assistant will receive the stitched avatar image.

Above this Python to achieve the full avatar of the friend of the splicing example (recommended) is all I have shared with you, I hope to be able to give you a reference, and I hope that you will support me more.