解决Python3用PIL的ImageFont输出中文乱码的问题
作者:小啊小木头 时间:2022-09-09 04:49:22
今天在用python3+ImageFont输出中文时,结果显示乱码
# coding:utf-8
from PIL import Image, ImageDraw, ImageFont
image= Image.new('RGB', (559, 320),(255,255,255))
draw = ImageDraw.Draw(image)
# draw.text()
font = ImageFont.truetype("arial", 40, encoding="unic") # 设置字体
draw.text((100, 50), "哈哈哈", 'black', font)
# del draw
image.show()
# printers = win32print.EnumPrinters(10)
# print printers
有个简单的解决方法,修改字体为simsun.ttc即可:
# coding:utf-8
from PIL import Image, ImageDraw, ImageFont
image= Image.new('RGB', (559, 320),(255,255,255))
draw = ImageDraw.Draw(image)
# draw.text()
font = ImageFont.truetype("simsun.ttc", 40, encoding="unic") # 设置字体
draw.text((100, 50), "哈哈哈", 'black', font)
# del draw
image.show()
# printers = win32print.EnumPrinters(10)
# print printers
来源:https://blog.csdn.net/lxfHaHaHa/article/details/87639291
标签:Python3,PIL,ImageFont,中文乱码
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
js页面文字选中后分享到新浪微博实现
2011-03-17 12:55:00
用Django实现一个可运行的区块链应用
2022-07-17 22:26:31
![](https://img.aspxhome.com/file/2023/3/101323_0s.jpg)
Python实现使用dir获取类的方法列表
2023-01-04 12:18:44
微信小程序顶部导航栏可滑动并选中放大
2023-08-23 18:49:59
![](https://img.aspxhome.com/file/2023/8/56168_0s.gif)
Sql Server “因为文件组primary已满,未能为数据库XX对象XX分配空间”问题的解决
2010-05-16 21:27:00
JS实现canvas简单小画板功能
2023-08-21 07:40:49
![](https://img.aspxhome.com/file/2023/1/56031_0s.jpg)
Ajax发明人:Ajax并不适合所有网站
2008-01-30 12:20:00
python sort、sort_index方法代码实例
2022-12-16 00:43:17
python模拟预测一下新型冠状病毒肺炎的数据
2023-12-17 05:09:15
![](https://img.aspxhome.com/file/2023/6/86676_0s.jpg)
Python中jieba库的使用方法
2021-06-23 13:47:24
![](https://img.aspxhome.com/file/2023/1/77821_0s.png)
对Python强大的可变参数传递机制详解
2021-06-23 02:54:09
plt.subplot()参数及使用介绍
2022-03-23 09:17:03
![](https://img.aspxhome.com/file/2023/4/105284_0s.png)
ubuntu系统下使用pm2设置nodejs开机自启动的方法
2023-10-02 22:23:16
CSS Shadow Practice
2009-04-01 18:37:00
不支持fsockopen但支持culr环境下下ucenter与modoer通讯问题
2023-09-11 00:33:45
详解python内置模块urllib
2022-11-18 21:34:10
![](https://img.aspxhome.com/file/2023/7/77627_0s.png)
Python 自动补全(vim)
2021-11-06 16:54:42
![](https://img.aspxhome.com/file/2023/4/93774_0s.jpg)
主流浏览器性能比较
2009-10-19 14:34:00
![](https://img.aspxhome.com/file/UploadPic/200910/19/15-02_performance_comparison_of_web_browsers_preview-60s.jpg)
Codeigniter发送邮件的方法
2023-11-15 05:08:25
JavaScript 经典实例日常收集整理(常用经典)
2023-09-15 07:40:56
![](https://img.aspxhome.com/file/2023/8/56118_0s.png)