From 8755b92c2e28564bba83b5bba4d4cc6aa58c18bf Mon Sep 17 00:00:00 2001 From: Joachim Date: Fri, 28 May 2021 21:40:20 +0200 Subject: [PATCH] Fix GitHub FileNotFoundError --- bookwyrm/preview_images.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/bookwyrm/preview_images.py b/bookwyrm/preview_images.py index 17511dde..624b6afe 100644 --- a/bookwyrm/preview_images.py +++ b/bookwyrm/preview_images.py @@ -103,17 +103,27 @@ def generate_instance_layer(content_width): if site.logo_small: logo_img = Image.open(site.logo_small) else: - static_path = os.path.join(settings.STATIC_ROOT, "images/logo-small.png") - logo_img = Image.open(static_path) + try: + static_path = os.path.join(settings.STATIC_ROOT, "images/logo-small.png") + logo_img = Image.open(static_path) + except FileNotFoundError: + logo_img = None instance_layer = Image.new("RGBA", (content_width, 62), color=TRANSPARENT_COLOR) - logo_img.thumbnail((50, 50), Image.ANTIALIAS) + instance_text_x = 0 - instance_layer.paste(logo_img, (0, 0)) + if logo_img: + logo_img.thumbnail((50, 50), Image.ANTIALIAS) + + instance_layer.paste(logo_img, (0, 0)) + + instance_text_x = instance_text_x + 60 instance_layer_draw = ImageDraw.Draw(instance_layer) - instance_layer_draw.text((60, 10), site.name, font=font_instance, fill=TEXT_COLOR) + instance_layer_draw.text( + (instance_text_x, 10), site.name, font=font_instance, fill=TEXT_COLOR + ) line_width = 50 + 10 + font_instance.getsize(site.name)[0]