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 · 1926 次点击
    这是一个创建于 1201 天前的主题,其中的信息可能已经有所发展或是发生改变。

    腾讯云最新优惠活动来了:云产品限时1折,云服务器低至88元/年 ,点击这里立即抢购:9i0i.cn/qcloud,更有2860元代金券免费领取,付款直接抵现金用,点击这里立即领取:9i0i.cn/qcloudquan

    (福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

    字体来自 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   ·   实用小工具   ·   2718 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:35 · PVG 18:35 · LAX 03:35 · JFK 06:35
    Developed with CodeLauncher
    ? Do have faith in what you're doing.


    http://www.vxiaotou.com