推荐学习书目
› 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 · Jan 26, 2021 · 3147 views
    This topic created in 2072 days ago, the information mentioned may be changed or developed.

    字体来自 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  
       Jan 26, 2021   ❤️ 1
    ImageFont.truetype('./PingFang.ttc', 60, index=2)
    加上 index 参数,从 0 尝试到 35 有多种可用的值。阅读源码文档,index 表示第几套字体,改变值的过程可以观察到文字粗细的变化。
    这个字体文件 /System/Library/Fonts/PingFang.ttc 大小 77Mb,观察下 windows 上的中文字体一套 10Mb 左右,所以这个大字体文件包含多个子字体文件,用默认的字体册程序打开,发现字体文件包含简体、繁、港,每种下面又分为常规、细、粗等。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1131 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 23:16 · PVG 07:16 · LAX 16:16 · JFK 19:16
    ♥ Do have faith in what you're doing.