Use Source Han Sans for preview images generation

This commit is contained in:
Joachim 2022-01-19 16:52:57 +01:00 committed by Joel Bradshaw
parent 284eb620dd
commit 6f5115c716
2 changed files with 11 additions and 9 deletions

View file

@ -29,23 +29,25 @@ margin = math.floor(IMG_HEIGHT / 10)
gutter = math.floor(margin / 2) gutter = math.floor(margin / 2)
inner_img_height = math.floor(IMG_HEIGHT * 0.8) inner_img_height = math.floor(IMG_HEIGHT * 0.8)
inner_img_width = math.floor(inner_img_height * 0.7) inner_img_width = math.floor(inner_img_height * 0.7)
font_dir = os.path.join(settings.STATIC_ROOT, "fonts/public_sans") font_dir = os.path.join(settings.STATIC_ROOT, "fonts/source_han_sans")
def get_font(font_name, size=28): def get_font(weight, size=28):
"""Loads custom font""" """Loads custom font"""
if font_name == "light": font_path = os.path.join(font_dir, "SourceHanSans-VF.ttf.ttc")
font_path = os.path.join(font_dir, "PublicSans-Light.ttf")
if font_name == "regular":
font_path = os.path.join(font_dir, "PublicSans-Regular.ttf")
elif font_name == "bold":
font_path = os.path.join(font_dir, "PublicSans-Bold.ttf")
try: try:
font = ImageFont.truetype(font_path, size) font = ImageFont.truetype(font_path, size)
except OSError: except OSError:
font = ImageFont.load_default() font = ImageFont.load_default()
if (weight == 'light'):
font.set_variation_by_name('Light')
if (weight == 'bold'):
font.set_variation_by_name('Bold')
if (weight == 'regular'):
font.set_variation_by_name('Regular')
return font return font

View file

@ -6,7 +6,7 @@ django-model-utils==4.0.0
environs==9.3.4 environs==9.3.4
flower==1.0.0 flower==1.0.0
Markdown==3.3.3 Markdown==3.3.3
Pillow>=8.2.0 Pillow>=9.0.0
psycopg2==2.8.4 psycopg2==2.8.4
pycryptodome==3.9.4 pycryptodome==3.9.4
python-dateutil==2.8.1 python-dateutil==2.8.1