python字体大小设置苹果电脑_在Mac上的Python /枕头中加载字体

The Pillow ImageFont documentation has a few examples of using different fonts, but they don't work "out of the box" on a Mac. It's probably not too hard to figure out where my system fonts are located, but I'm lazy and would like a simple example that I can just edit.

So: how can I use Pillow on a Mac to write some text in a different font and size from the default?

解决方案

Ok, "Lazy One" ;-) Here is an example:

from PIL import Image, ImageFont, ImageDraw

# Make a red canvas and get a drawing context to it

img = Image.new(mode='RGB', size=(500, 200), color=(255,0,0))

draw = ImageDraw.Draw(img)

# Get a "Chalkduster" TTF

chalk = ImageFont.truetype("Chalkduster.ttf",16)

# Get a "Keyboard" TTF

kbd = ImageFont.truetype("Keybo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值