将字体从URL加载到枕头 [英] Loading font from URL to Pillow

查看:67
本文介绍了将字体从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)

这篇关于将字体从URL加载到枕头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆