【轉】Python微信好友頭像拼接圖


  

  轉自: Python微信好友頭像拼接圖

  今天在朋友圈看到有人發了微信好友拼接圖,心里滿是新奇,看了下評論才知道用Python寫的。心里癢癢,立馬就安裝了下Python

  安裝好了之后,看了下大神的代碼,基本上能夠讀得懂(語言都是想通的嘛!),然后就嘗試在小黑窗運行了,結果報錯了!

rawmode = RAWMODE[im.mode] KeyError: 'RGBA'

  這種錯誤看的我是一臉懵逼啊,搜索了半天也沒看到什么解決方案,結果就在寧外一篇博客的評論里面發現了解決方法,結果成功運行,還是66的。

  

 

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 = 0
for i in friends:
    img = itchat.get_head_img(userName=i["UserName"])
    fileImage = open('D:' + "/wechat_head_image/" + str(num) + ".jpg",'wb')
    fileImage.write(img)
    fileImage.close()
    num += 1

ls = os.listdir('D:/wechat_head_image')
each_size = int(math.sqrt(float(640*640)/len(ls)))
lines = int(640/each_size)
image = Image.new('RGB', (640, 640))
x = 0
y = 0
for i in range(0,len(ls)+1):
    try:
        img = Image.open('D:/wechat_head_image' + "/" + 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 += 1
        if x == lines:
            x = 0
            y += 1
image.save('D:/wechat_head_image/all' + "/" + "all.jpg")
itchat.send_image('D:/wechat_head_image/all' + "/" + "all.jpg", 'filehelper')

  運行后效果截圖

 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM