From 77bdfae24843e163052479730210177103b123aa Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Sun, 22 Oct 2023 21:31:51 -0600 Subject: Use Dall-E to generate images --- Resources/DallE3Base/posts/2023-10-04-bomb-lab.png | Bin 0 -> 1720442 bytes .../DallE3Base/posts/2023-10-05-attack-lab.png | Bin 0 -> 1702606 bytes .../posts/2023-10-22-search-by-flair-reddit.png | Bin 0 -> 2202291 bytes .../images/opengraph/posts/2023-10-04-bomb-lab.png | Bin 18697 -> 692994 bytes .../opengraph/posts/2023-10-05-attack-lab.png | Bin 2855252 -> 695415 bytes .../posts/2023-10-22-search-by-flair-reddit.png | Bin 23362 -> 854300 bytes docs/DallE3Base/posts/2023-10-04-bomb-lab.png | Bin 0 -> 1720442 bytes docs/DallE3Base/posts/2023-10-05-attack-lab.png | Bin 0 -> 1702606 bytes .../posts/2023-10-22-search-by-flair-reddit.png | Bin 0 -> 2202291 bytes docs/feed.rss | 4 +- .../images/opengraph/posts/2023-10-04-bomb-lab.png | Bin 18697 -> 692994 bytes .../opengraph/posts/2023-10-05-attack-lab.png | Bin 2855252 -> 695415 bytes .../posts/2023-10-22-search-by-flair-reddit.png | Bin 23362 -> 854300 bytes generate_me.py | 96 ++++++++++++++------- helper_libs/image_utils.py | 9 +- 15 files changed, 72 insertions(+), 37 deletions(-) create mode 100644 Resources/DallE3Base/posts/2023-10-04-bomb-lab.png create mode 100644 Resources/DallE3Base/posts/2023-10-05-attack-lab.png create mode 100644 Resources/DallE3Base/posts/2023-10-22-search-by-flair-reddit.png create mode 100644 docs/DallE3Base/posts/2023-10-04-bomb-lab.png create mode 100644 docs/DallE3Base/posts/2023-10-05-attack-lab.png create mode 100644 docs/DallE3Base/posts/2023-10-22-search-by-flair-reddit.png diff --git a/Resources/DallE3Base/posts/2023-10-04-bomb-lab.png b/Resources/DallE3Base/posts/2023-10-04-bomb-lab.png new file mode 100644 index 0000000..e022194 Binary files /dev/null and b/Resources/DallE3Base/posts/2023-10-04-bomb-lab.png differ diff --git a/Resources/DallE3Base/posts/2023-10-05-attack-lab.png b/Resources/DallE3Base/posts/2023-10-05-attack-lab.png new file mode 100644 index 0000000..aa4deae Binary files /dev/null and b/Resources/DallE3Base/posts/2023-10-05-attack-lab.png differ diff --git a/Resources/DallE3Base/posts/2023-10-22-search-by-flair-reddit.png b/Resources/DallE3Base/posts/2023-10-22-search-by-flair-reddit.png new file mode 100644 index 0000000..320d583 Binary files /dev/null and b/Resources/DallE3Base/posts/2023-10-22-search-by-flair-reddit.png differ diff --git a/Resources/images/opengraph/posts/2023-10-04-bomb-lab.png b/Resources/images/opengraph/posts/2023-10-04-bomb-lab.png index 3453c2a..551900e 100644 Binary files a/Resources/images/opengraph/posts/2023-10-04-bomb-lab.png and b/Resources/images/opengraph/posts/2023-10-04-bomb-lab.png differ diff --git a/Resources/images/opengraph/posts/2023-10-05-attack-lab.png b/Resources/images/opengraph/posts/2023-10-05-attack-lab.png index d55fc80..2097209 100644 Binary files a/Resources/images/opengraph/posts/2023-10-05-attack-lab.png and b/Resources/images/opengraph/posts/2023-10-05-attack-lab.png differ diff --git a/Resources/images/opengraph/posts/2023-10-22-search-by-flair-reddit.png b/Resources/images/opengraph/posts/2023-10-22-search-by-flair-reddit.png index 7b44d6c..91e8370 100644 Binary files a/Resources/images/opengraph/posts/2023-10-22-search-by-flair-reddit.png and b/Resources/images/opengraph/posts/2023-10-22-search-by-flair-reddit.png differ diff --git a/docs/DallE3Base/posts/2023-10-04-bomb-lab.png b/docs/DallE3Base/posts/2023-10-04-bomb-lab.png new file mode 100644 index 0000000..e022194 Binary files /dev/null and b/docs/DallE3Base/posts/2023-10-04-bomb-lab.png differ diff --git a/docs/DallE3Base/posts/2023-10-05-attack-lab.png b/docs/DallE3Base/posts/2023-10-05-attack-lab.png new file mode 100644 index 0000000..aa4deae Binary files /dev/null and b/docs/DallE3Base/posts/2023-10-05-attack-lab.png differ diff --git a/docs/DallE3Base/posts/2023-10-22-search-by-flair-reddit.png b/docs/DallE3Base/posts/2023-10-22-search-by-flair-reddit.png new file mode 100644 index 0000000..320d583 Binary files /dev/null and b/docs/DallE3Base/posts/2023-10-22-search-by-flair-reddit.png differ diff --git a/docs/feed.rss b/docs/feed.rss index 755c84c..bcafcbe 100644 --- a/docs/feed.rss +++ b/docs/feed.rss @@ -4,8 +4,8 @@ Navan's Archive Rare Tips, Tricks and Posts https://web.navan.dev/en - Sun, 22 Oct 2023 19:29:39 -0000 - Sun, 22 Oct 2023 19:29:39 -0000 + Sun, 22 Oct 2023 21:26:58 -0000 + Sun, 22 Oct 2023 21:26:58 -0000 250 diff --git a/docs/images/opengraph/posts/2023-10-04-bomb-lab.png b/docs/images/opengraph/posts/2023-10-04-bomb-lab.png index 3453c2a..551900e 100644 Binary files a/docs/images/opengraph/posts/2023-10-04-bomb-lab.png and b/docs/images/opengraph/posts/2023-10-04-bomb-lab.png differ diff --git a/docs/images/opengraph/posts/2023-10-05-attack-lab.png b/docs/images/opengraph/posts/2023-10-05-attack-lab.png index d55fc80..2097209 100644 Binary files a/docs/images/opengraph/posts/2023-10-05-attack-lab.png and b/docs/images/opengraph/posts/2023-10-05-attack-lab.png differ diff --git a/docs/images/opengraph/posts/2023-10-22-search-by-flair-reddit.png b/docs/images/opengraph/posts/2023-10-22-search-by-flair-reddit.png index 7b44d6c..91e8370 100644 Binary files a/docs/images/opengraph/posts/2023-10-22-search-by-flair-reddit.png and b/docs/images/opengraph/posts/2023-10-22-search-by-flair-reddit.png differ diff --git a/generate_me.py b/generate_me.py index 658b362..fa39bf9 100644 --- a/generate_me.py +++ b/generate_me.py @@ -5,6 +5,7 @@ from distutils.dir_util import copy_tree import datetime import email.utils from helper_libs.image_utils import ImageText +from PIL import Image templates = Environment(loader=FileSystemLoader("templates")) src_folder = "Content" @@ -15,8 +16,8 @@ f_title = "Navan's Archive" f_description = "Rare Tips, Tricks and Posts" f_date = email.utils.format_datetime(datetime.datetime.now()) -image_title_color = (74, 74, 74) -image_line_color = (29, 116, 132) +image_title_color = (49,31,19) #(74, 74, 74) +image_line_color = (176,113,84) #(29, 116, 132) image_title_font = "fonts/futura_bold.ttf" image_text_font = "fonts/futura_light.ttf" @@ -97,37 +98,68 @@ for x in os.walk(src_folder): # Check if image exists if not os.path.exists(to_write_path): + print(print("Generating Image for {}".format(fpath))) 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", - ) + dall_e_image = to_write_path.replace("images/opengraph","DallE3Base") + if (os.path.exists(dall_e_image)): + print("Found DallE3Base Image") + img = ImageText((1200,630), background=(248,247,240)) + dall_e_image_file = Image.open(dall_e_image) + dall_e_image_file = dall_e_image_file.resize((630,630)) + img.paste(dall_e_image_file, (570,0)) + img.write_text_box( + (35, 50), + _post_title, + box_width=500, + font_filename=image_title_font, + font_size=65, + color=image_title_color, + place="center", + ) + img.line( + shape=[(500, 400), (70,400)], fill=image_line_color, width=5 + ) + img.write_text_box( + (35, 435), + _post["description"], + box_width=500, + font_filename=image_text_font, + font_size=32, + color=(0, 0, 0), + place="center", + ) + else: + #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: diff --git a/helper_libs/image_utils.py b/helper_libs/image_utils.py index 70eaebb..501b6d0 100644 --- a/helper_libs/image_utils.py +++ b/helper_libs/image_utils.py @@ -20,12 +20,15 @@ class ImageText(object): self.draw = ImageDraw.Draw(self.image) self.encoding = encoding - def line(self, shape, fill): - self.draw.line(shape,fill=fill, width=10) + def line(self, shape, fill, width=10): + self.draw.line(shape,fill=fill, width=width) def save(self, filename=None): self.image.save(filename or self.filename) + def paste(self, image, coords): + self.image.paste(image, coords) + def get_font_size(self, text, font, max_width=None, max_height=None): if max_width is None and max_height is None: raise ValueError('You need to pass max_width or max_height') @@ -122,4 +125,4 @@ class ImageText(object): last_word_x = x + box_width - last_word_size[0] self.write_text((last_word_x, height), words[-1], font_filename, font_size, color) - return (box_width, height - y) \ No newline at end of file + return (box_width, height - y) -- cgit v1.2.3