Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use Python to make WeChat friend Image and Family Photo

Shulou Source: shulou.com Published: 2022-06-01 10:11:46 09月29日 Update

In this issue, the editor will bring you about how to use Python to make WeChat friend images of the whole family. The article is rich in content and analyzes and narrates for you from a professional point of view. I hope you can get something after reading this article.

Today to bring you a small Python actual combat project, using Python to make Wechat friends image family photos, do you want to try it?

Project environment

Locale: Python 3.6

Import libraries: itchat, PIL

After the avatar collection is completed, we also have to compose all the avatars, so we also introduce a PIL image processing library.

Please use the pip command to install the library mentioned above and import it.

Import itchatimport PIL.Image as Imageimport mathimport os

Log in to Wechat

First of all, we use the itchat library to log in to our Wechat and get all our friend information.

Itchat.auto_login (True) # Log in to Wechat friends = itchat.get_friends (update=True) [0:]

Save the avatar

In the itchat library, there is a built-in method to obtain Wechat avatar: get_head_img, which can be called directly. After getting the avatar, we can name it incrementally and save it in our directory.

In the above function to save the picture, we see that there is a parameter, which is the home directory where the picture is saved. If this home directory does not exist, we will create one. We write a separate function to define this directory and return it.

With the above two simple functions, we save all the images of our Wechat friends to the specified directory.

Avatar synthesis

The next thing we need to do is to make all these avatars into "family photos".

At this point, it's time for another library to come out, which is the image processing library: PIL library.

Next, use this library to create a new picture with a white background, and fill all the pictures into the big canvas according to the size of the picture. When the processing is finished, save the "family photo" in the same directory as the avatar.

The above is the editor for you to share how to use Python to make WeChat friend images of the whole family, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Tags: Avatar picture directory family family photo image friend processing function login and then content that is environment project analysis professional two small and medium information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi vpn Shulou Technology OPPO Reno Xiaomi