1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| from PIL import Image, ImageDraw, ImageFont import glob import itchat
itchat.auto_login(hotReload=True)
def generatePic(name): pattern = 'news.jpg' setFont = ImageFont.truetype('simkai.ttf', 35) fillColor = "red" for img in glob.glob(pattern): image = Image.open(img) if image.mode == "P": image = image.convert('RGB') draw = ImageDraw.Draw(image) draw.text((200, 370), u'祝愿'+name+':',font=setFont,fill=fillColor) mywidth,myheight,lineheight = 235,460,70 draw.text((mywidth, myheight), u'岁华新至,除夕乐融,', font=setFont, fill=fillColor) draw.text((mywidth, myheight+lineheight), u'喜乐平安,诸事顺遂,', font=setFont, fill=fillColor) draw.text((mywidth, myheight+lineheight*2), u'吉吉利利,百事如意,', font=setFont, fill=fillColor) draw.text((mywidth, myheight+lineheight*3), u'家兴百和,万福骈臻。', font=setFont, fill=fillColor) draw.text((mywidth, myheight+lineheight*5), u'署名', font=setFont, fill=fillColor) image.save("mycard2.jpg") return "mycard2.jpg"
friends = itchat.get_friends(update=True)[:]
RemarkNames = ['a1文杰']
for person in RemarkNames: users=itchat.search_friends(person) userName= users[0]['UserName'] picfile = generatePic(person[-2:])
try: itchat.send('Hey'+person[-2:]+'~ Happy New Year!', toUserName=userName) print("发送给" + person + "的祝福语文字 成功") except: print("发送给"+person+"的祝福语文字 失败")
try: itchat.send_image(picfile,toUserName=userName) print("发送给"+person+"的祝福语图片 成功") except: print("发送给"+person+"的祝福语图片 失败")
|