diff options
-rw-r--r-- | generate_me.py | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/generate_me.py b/generate_me.py index 3bd9178..58a644e 100644 --- a/generate_me.py +++ b/generate_me.py @@ -71,23 +71,26 @@ for x in os.walk(src_folder): _post["image_link"] = "/images/opengraph" + fpath.replace(src_folder,"").replace("md","png") to_write_path = "./Resources" + _post["image_link"] - img = ImageText((1200,630), background=(238,238,238)) - img.write_text_box((100, 50), _post_title, box_width=1000, font_filename=image_title_font, - font_size=65, color=image_title_color, place='center') - img.line(shape=[(400, 400), (800, 400)],fill=image_line_color) - img.write_text_box((100, 430), f'Tags: {", ".join(_post["tags"])}', box_width=1000, font_filename=image_text_font, - font_size=32, color=(0,0,0), place='left') - img.write_text_box((100, 400), f'Date: {_post["date"]}', box_width=1000, font_filename=image_text_font, - font_size=32, color=(0,0,0), place='left') - try: - img.save(to_write_path) - except FileNotFoundError as e: - if not os.path.exists(to_write_path.rsplit("/",1)[0]): - os.makedirs(to_write_path.rsplit("/",1)[0]) + + # Check if image exists + if not os.path.exists(to_write_path): + img = ImageText((1200,630), background=(238,238,238)) + img.write_text_box((100, 50), _post_title, box_width=1000, font_filename=image_title_font, + font_size=65, color=image_title_color, place='center') + img.line(shape=[(400, 400), (800, 400)],fill=image_line_color) + img.write_text_box((100, 430), f'Tags: {", ".join(_post["tags"])}', box_width=1000, font_filename=image_text_font, + font_size=32, color=(0,0,0), place='left') + img.write_text_box((100, 400), f'Date: {_post["date"]}', box_width=1000, font_filename=image_text_font, + font_size=32, color=(0,0,0), place='left') + try: img.save(to_write_path) - else: - print(e) - exit(1) + except FileNotFoundError as e: + if not os.path.exists(to_write_path.rsplit("/",1)[0]): + os.makedirs(to_write_path.rsplit("/",1)[0]) + img.save(to_write_path) + else: + print(e) + exit(1) _post["image_link"] = base_link[:-1] + _post["image_link"] |