Restore _get_font_path because the font needs to be known in order to fit the text into the frame properly.
@@ -44,6 +44,25 @@ def _smaller_dimension(width, height):
return smaller_dimension
+def _get_font_path(monospace=False):
+ """
+ Return the path to the TTF font file
+ :param monospace: True for monospaced font, False for variable-width font
+ :return: the path to the TTF font file
+ """
+
+ font_name = 'SourceCodePro-Bold.ttf' \
+ if monospace \
+ else 'SourceSansPro-Bold.ttf'
+ font_path = os.path.join(
+ os.path.dirname(__file__),
+ 'fonts',
+ font_name
+ )
+
+ return font_path
+
+
def _fit_in_width(text, font, max_width):
"""
Break the given text so that it fits in the given space
@@ -181,10 +200,7 @@ def _print_attribution_on_image(img, image_info):
if Dimension.WIDTH in smaller_dimension \
else width
- try:
- font = ImageFont.truetype('SourceSansPro-Bold.ttf', size=font_size)
- except OSError:
- font = None
+ font = ImageFont.truetype(_get_font_path(), size=font_size)
text = _get_attribution_text(image_info)
text = _fit_in_width(text, font, new_width)
