python3下的PIL叫做 pillow
python -m pip install pillow
创建目录 fonts,把微软雅黑字体放到下面。msyh.ttf
1
2
3
4
5
6
7
8
9
10
11
12
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
os
from
PIL
import
Image,ImageFont,ImageDraw
l
=
[
1
,
23
,
4
]
text
=
u
"这是一段测试文本,test 123。{}\n "
.
format
(l[
1
])
im
=
Image.new(
"RGB"
, (
300
,
50
), (
255
,
255
,
255
))
dr
=
ImageDraw.Draw(im)
font
=
ImageFont.truetype(os.path.join(
"fonts"
,
"msyh.ttf"
),
14
)
dr.text((
10
,
5
), text, font
=
font, fill
=
"#000000"
)
im.show()
im.save(
"t.png"
)
|
本文转自 295631788 51CTO博客,原文链接:http://blog.51cto.com/hequan/1899899,如需转载请自行联系原作者