Instead of downloading the font locally and link it to ImageFont.truetyp() to be like this:
JavaScript
x
3
1
from pillow import ImageFont
2
font = ImageFont.truetype('Roboto-Regular.ttf', size=10)
3
Can I do something like this:
JavaScript
1
3
1
from pillow import ImageFont
2
font = ImageFont.truetype('https://github.com/googlefonts/roboto/blob/master/src/hinted/Roboto-Regular.ttf', size=10)
3
Advertisement
Answer
ImageFont.true_type
takes a file-like object.
Python’s standard library, urllib.request.urlopen
returns a file-like object.
The following should work:
JavaScript
1
6
1
from pillow import ImageFont
2
from urllib.request import urlopen
3
4
truetype_url = 'https://github.com/googlefonts/roboto/blob/master/src/hinted/Roboto-Regular.ttf?raw=true'
5
font = ImageFont.truetype(urlopen(truetype_url), size=10)
6
edit: As @flyer2403 answered, to make that particular url work you need to add ?raw=true
to the end.