V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
sockball07
V2EX  ›  Python

PIL 库添加文字使用苹方字体时不能显示杀字?

  •  
  •   sockball07 · 2021-01-26 21:21:30 +08:00 · 1874 次点击
    这是一个创建于 1157 天前的主题,其中的信息可能已经有所发展或是发生改变。

    字体来自 macbook, 还有什么字不能显示暂时未知... 繁体可显示, 换成其他字体可正常显示

    from PIL import ImageFont, ImageDraw, Image
    
    filename = './sample.jpg'
    sample = Image.open(filename)
    draw = ImageDraw.Draw(sample)
    
    draw.text((0, 50), '我不会杀人', font=ImageFont.truetype('./PingFang.ttc', 60), fill=(0, 0, 0))
    sample.save('./other/result.jpg')
    

    sample.jpg

    result.jpg

    RyougiShiki
        1
    RyougiShiki  
       2021-01-26 22:08:57 +08:00   ❤️ 1
    ImageFont.truetype('./PingFang.ttc', 60, index=2)
    加上 index 参数,从 0 尝试到 35 有多种可用的值。阅读源码文档,index 表示第几套字体,改变值的过程可以观察到文字粗细的变化。
    这个字体文件 /System/Library/Fonts/PingFang.ttc 大小 77Mb,观察下 windows 上的中文字体一套 10Mb 左右,所以这个大字体文件包含多个子字体文件,用默认的字体册程序打开,发现字体文件包含简体、繁、港,每种下面又分为常规、细、粗等。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3349 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 13:37 · PVG 21:37 · LAX 06:37 · JFK 09:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.