Skip to content

Commit

Permalink
Merge pull request Show-Me-the-Code#92 from kentsay/master
Browse files Browse the repository at this point in the history
Creating solution for show-me-the-code in Python
  • Loading branch information
horx committed Apr 23, 2015
2 parents ea9f186 + 4144fd7 commit 215720b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions kentsay/0001/add_num2img.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Question:
第 0000 题:将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。
"""

import sys
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

def add_number2img(image, number):
font = ImageFont.truetype("/Library/Fonts/Chalkduster.ttf", 28)
draw = ImageDraw.Draw(image)
draw.text((200,0), str(number),(255, 255, 255), font=font)
draw = ImageDraw.Draw(image)
image.save("mask_with_num.png")
image.show()


origin = Image.open("mask.png")
add_number2img(origin, sys.argv[1])
Binary file added kentsay/0001/mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added kentsay/0001/mask_with_num.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 215720b

Please sign in to comment.