0、作者不承担任何法律责任!仅供学习交流使用,严禁用于其他用途
1、info.txt
个人信息,nickname为你的微信昵称
2、raw.PNG
以此图片为底图制作最终图片
3、touxiang.jpg
微信头像
4、源码QNDXX.py
import requests
import re
from PIL import Image, ImageDraw, ImageFont
def get_url():
html = requests.get('http://news.cyol.com/node_67071.htm').text
url = re.findall('href="(.*?)" target', html)[0]
return url
def get_id(url):
the_id = url.split('/')[-2]
return the_id
def get_icon(the_id):
addr = 'http://h5.cyol.com/special/daxuexi/%s/images/icon.jpg' % the_id
icon = requests.get(addr).content
with open('icon.jpg', 'wb') as f:
f.write(icon)
def get_end(the_id):
addr = 'http://h5.cyol.com/special/daxuexi/%s/images/end.jpg' % the_id
end = requests.get(addr).content
with open('end.jpg', 'wb') as f:
f.write(end)
def get_info(file='info.txt'):
with open(file, 'r', encoding='utf-8') as f:
info = []
for line in f.readlines():
line = line.strip('\n')
i = line.split(':')
info.append(i)
info = dict(info)
return info
def change(raw='raw.png', icon='icon.jpg', touxiang='touxiang.jpg'):
result = Image.open(raw)
icon = (Image.open(icon)).resize((80, 80), resample=0)
touxiang = (Image.open(touxiang)).resize((80, 80), resample=0)
result.paste(icon, (123, 330))
result.paste(touxiang, (13, 132))
'''========================以下为加文字部分==========================='''
info = get_info()
font = ImageFont.truetype('C:/windows/fonts/Simhei.ttf', size=32)
draw = ImageDraw.Draw(result)
draw.text((215, 355), info['share'], fill='black', font=font)
draw.text((116, 135), info['nickname'], fill=(87, 107, 149), font=font)
draw.text((116, 190), info['school'], fill='black', font=font)
draw.text((116, 230), info['name'], fill='black', font=font)
draw.text((116, 270), info['stu_num'], fill=(87, 107, 149), font=font)
result.save('result.png')
def run():
url = get_url()
Id = get_id(url)
get_icon(Id)
get_end(Id)
change()
if __name__ == '__main__':
run()
5、