zoukankan      html  css  js  c++  java
  • 微信图片墙

    有趣的事,Python永远不会缺席!

    如需转发,请注明出处:小婷儿的python  https://www.cnblogs.com/xxtalhr/p/10890921.html 

    一、制作微信头像墙(方形)

      1、安装库   

    1 pip install wxpy
    2 
    3 pip install pillow

      2、代码实现

     1 # coding: utf-8
     2 from wxpy import Bot, Chat
     3 
     4 import math
     5 import os
     6 from PIL import Image
     7 
     8 
     9 class WxFriendImage(Chat):
    10     @staticmethod
    11     def get_image():
    12         path = os.path.abspath('.')
    13         bot = Bot()  # 机器人对象
    14         friends = bot.friends(update=True)
    15 
    16         dirs = path + '\wx-tx'
    17         if not os.path.exists(dirs):
    18             os.mkdir('wx-tx')
    19 
    20         index = 0
    21         for friend in friends:
    22             print(f'正在保存{friend.nick_name}的微信头像')
    23             friend.get_avatar(dirs + '\' + f'{str(index)}.jpg')
    24             index += 1
    25 
    26         return dirs
    27 
    28     @staticmethod
    29     def composite_image(dirs):
    30         images_list = os.listdir(dirs)
    31         images_list.sort(key=lambda x: int(x[:-4]))  # 根据头像名称排序
    32         length = len(images_list)  # 头像总数
    33         image_size = 2560
    34         # 每个头像大小
    35         each_size = math.ceil(image_size / math.floor(math.sqrt(length)))
    36         lines = math.ceil(math.sqrt(length))  # 列数
    37         rows = math.ceil(math.sqrt(length))  # 行数
    38         image = Image.new('RGB', (each_size * lines, each_size * rows))
    39         row = 0
    40         line = 0
    41         os.chdir(dirs)
    42         for file in images_list:
    43             try:
    44                 with Image.open(file) as img:
    45                     img = img.resize((each_size, each_size))
    46                     image.paste(img, (line * each_size, row * each_size))
    47                     line += 1
    48                     if line == lines:
    49                         line = 0
    50                         row += 1
    51             except IOError:
    52                 print(f'头像{file}异常,请查看')
    53                 continue
    54         img = image.save(os.getcwd() + '/wx-txq.png')
    55         if not img:
    56             print('所有的微信头像已合成微信好友照片墙,请查阅wx-txq.png!')
    57 
    58 
    59 def main():
    60     dirs = WxFriendImage.get_image()
    61     WxFriendImage.composite_image(dirs)
    62 
    63 
    64 if __name__ == '__main__':
    65     main()

    二、制作微信头像墙(圆形)

     (待更新。。。。)

    三、建 exe 程序生成照片墙

      除了用代码方式生成外,还可以建一个 .exe 的程序,在电脑点击运行就完事了,下面分别详细的给大家讲解是如何实现的

      1、 安装库   

    1 pip install pyinstaller

       2、exe程序制作

     
    1 #pyinstaller -F file_path
    2 
    3 pyinstaller -F C:Analysispycharmpython_wx-tx.py

      

                               。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

    3、生成照片墙

     
     
     

    好了,以上就是用python合成微信好友头像的方法

    合成之后,可以发到自己的朋友圈,让别人来找找自己的头像在哪,顺便自己还能装个逼,哈哈~`

    觉得对你有用,就帮忙点个赞呗…

  • 相关阅读:
    JEDEC标准(JESD216)S FDP对串行Flash在系统中的应用
    Gerrit使用简介
    Gerrit2安装配置
    SSH原理与运用(二):远程操作与端口转发
    SSH原理与运用(一):远程登录
    常用的几个工具网站
    MQTT、CoAP
    Gerrit代码Review实战
    net share
    Gitlab+Gerrit+Jenkins完整对接
  • 原文地址:https://www.cnblogs.com/pythonbao/p/10890921.html
Copyright © 2011-2022 走看看