Share Python How to achieve avatar splicing technology/

Source: Internet
Author: User

Friend full head

Words don't say much, directly on the code

Import Itchatimport Mathimport PIL. Image as Imageimport ositchat.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 (' folder ' + '/' + str (num) + ". jpg", ' WB ')    Fileimage.write (img)    fileimage.close ()    num + = 1ls = Os.listdir (' folder ') 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 (' folder ' + '/' + str (i) + ". jpg")    except Ioerror:print ("Error") Else:        img = IM G.resize ((Each_size, each_size), Image.antialias)        Image.paste (IMG, (x * each_size, Y * each_size)) x + = 1if x = = lines: x = 0y + = 1image.save (' folder ' + '/' + ' all.jpg ') itchat.send_image (' folder ' + '/' + ' all.jpg ', ' filehelper ')

Code run requires two libraries to be installed

Pip Install Itchatpip Install Pillow

If the PIP installation option does not tick when you install Python, install PIP first.
Installation of Python and Pip


Itchat Official Introduction

When the code runs, you will see the log-in QR code, and with a sweep, you can view the progress of the process. Your file transfer Assistant will receive a good picture of your avatar.

You are welcome to join the Learning Exchange Group if you encounter any problems or want to acquire learning resources in the learning process.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.