Skip to content

Commit 5a2186e

Browse files
committed
Merge pull request Show-Me-the-Code#1 from Lupino/master
First anwser
2 parents 3836073 + 9161e49 commit 5a2186e

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎0000/CALIBRI.TTF‎

792 KB
Binary file not shown.

‎0000/image.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from PIL import Image, ImageDraw, ImageFont
2+
import urllib
3+
import urllib.request
4+
from io import BytesIO
5+
6+
# down load image avatar
7+
avatar = 'https://avatars3.githubusercontent.com/u/1332618?v=3&s=460'
8+
rsp = urllib.request.urlopen(avatar)
9+
data = rsp.read()
10+
11+
fp = BytesIO()
12+
fp.write(data)
13+
fp.seek(0, 0)
14+
image = Image.open(fp)
15+
image.show()
16+
17+
base = image.convert('RGBA')
18+
19+
# make a blank image for the text, initialized to transparent text color
20+
txt = Image.new('RGBA', base.size, (255, 255, 255, 0))
21+
22+
# get a font
23+
fnt = ImageFont.truetype('CALIBRI.TTF', 60)
24+
fnt_size = fnt.getsize("4")
25+
26+
d = ImageDraw.Draw(txt)
27+
d.text((image.size[0] - fnt_size[0] - 20, 20), "4", fill=(255, 0, 0, 255), font=fnt)
28+
29+
out = Image.alpha_composite(base, txt)
30+
31+
out.show()

0 commit comments

Comments
 (0)