The first 0000 topic
Put your QQ Head portrait ( Or Weibo / Letterhead ) Add a red number to the top right corner , It is similar to the prompt effect of the amount of unread information on wechat . Similar to the effect in the picture .
from PIL import Image, ImageDraw, ImageColor, ImageFont
def add_num(img):
draw = ImageDraw.Draw(img)
font1 = ImageFont.truetype('/System/Library/Fonts/Apple Symbols.ttf', size=40)
fillcolor = ImageColor.colormap.get('red')
width, height = img.size
draw.text((width-30, 0), '1', font=font1, fill=fillcolor)
# On the new object (width-30, 0) Red at the beginning “1”
img.save('result.jpg', 'jpeg')
return 0
if __name__ == '__main__':
image = Image.open('test.jpg')
add_num(image)
PIL(Python Image Library),Python Image processing standard library of the platform .
Image.open()
img.save()
width, height = img.size
ImageDraw The module provides a simple representation of the image object 2D draw .
draw = ImageDraw.Draw(img)
ImageFont Modular truetype function
ImageFont.truetype(file,size)
ImageColor
原文轉載自「劉悅的技術博客」https://v3u.cn/a