将字体从URL加载到枕头
问题描述:
有没有一种方法可以直接从url(最好是Google Colab)加载带有Pillow库的字体?我尝试过类似的
Is there a way to load a font with Pillow library directly from url, preferably into Google Colab? I tried something like
从PIL导入Image,ImageDraw,ImageFont
ImageFont.truetype(" https://github.com/googlefonts/roboto/blob/master/src/hinted/Roboto-Regular.ttf?raw = true",15)
但是我得到了 OSError:无法打开资源的错误.我也尝试过Google字体,但无济于事.
Yet I get an error of OSError: cannot open resource. I tried with Google Fonts too, but to no avail.
答
尝试如下:
import requests
from io import BytesIO
req = requests.get("https://github.com/googlefonts/roboto/blob/master/src/hinted/Roboto-Regular.ttf?raw=true")
font = ImageFont.truetype(BytesIO(req.content), 72)