Skip to content

Commit 551c5d1

Browse files
author
key
committed
完成第一题
1 parent b998901 commit 551c5d1

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

keysona/0000/0000.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# @Author: key
4+
# @Date: 2015-11-16 15:48:35
5+
# @Last Modified by: key
6+
# @Last Modified time: 2015-11-16 23:10:41
7+
8+
#---------------------------------
9+
#第 0000 题:将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。 类似于图中效果
10+
#---------------------------------
11+
12+
import cv2
13+
from PIL import Image,ImageFont,ImageDraw
14+
15+
DEBUG = True
16+
17+
#The picture size is 200px*200px
18+
19+
#opencv 3.0
20+
def opencv(filename,num):
21+
img = cv2.imread(filename,1)
22+
font = cv2.FONT_HERSHEY_PLAIN
23+
width,height,channel = img.shape
24+
cv2.putText(img,str(num),(int(width*5/6),int(height/4)),font,3,(0,0,255),2,cv2.LINE_AA)
25+
cv2.imwrite("result_opencv.png",img)
26+
if DEBUG:
27+
cv2.imshow("Key",img)
28+
cv2.waitKey(0)
29+
cv2.destroyAllWindows()
30+
31+
zho
32+
#Pillow
33+
def pillow(filename,num):
34+
img = Image.open(filename)
35+
x,y = img.size
36+
font = ImageFont.truetype("arial.ttf",int(x/3))
37+
ImageDraw.Draw(img).text((x*4/5,0),str(num),font=font,fill = 'red')
38+
img.save("result_pillow.png",)
39+
if DEBUG:
40+
img.show()
41+
42+
if __name__ == '__main__':
43+
opencv("alice_icon_sm.jpg",4)
44+
pillow("alice_icon_sm.jpg",4)
45+
46+
47+
48+

keysona/0000/arial.ttf

754 KB
Binary file not shown.

0 commit comments

Comments
 (0)