diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2023-10-22 21:31:51 -0600 |
---|---|---|
committer | Navan Chauhan <navanchauhan@gmail.com> | 2023-10-22 21:31:51 -0600 |
commit | 77bdfae24843e163052479730210177103b123aa (patch) | |
tree | 53eb4890dbc43ae1f60abe2774f65042d068d0d5 | |
parent | b51c8eb0e6e37682e9f5dfa43fedfce665e9beb7 (diff) |
Use Dall-E to generate images
15 files changed, 72 insertions, 37 deletions
diff --git a/Resources/DallE3Base/posts/2023-10-04-bomb-lab.png b/Resources/DallE3Base/posts/2023-10-04-bomb-lab.png Binary files differnew file mode 100644 index 0000000..e022194 --- /dev/null +++ b/Resources/DallE3Base/posts/2023-10-04-bomb-lab.png diff --git a/Resources/DallE3Base/posts/2023-10-05-attack-lab.png b/Resources/DallE3Base/posts/2023-10-05-attack-lab.png Binary files differnew file mode 100644 index 0000000..aa4deae --- /dev/null +++ b/Resources/DallE3Base/posts/2023-10-05-attack-lab.png 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 Binary files differnew file mode 100644 index 0000000..320d583 --- /dev/null +++ b/Resources/DallE3Base/posts/2023-10-22-search-by-flair-reddit.png diff --git a/Resources/images/opengraph/posts/2023-10-04-bomb-lab.png b/Resources/images/opengraph/posts/2023-10-04-bomb-lab.png Binary files differindex 3453c2a..551900e 100644 --- a/Resources/images/opengraph/posts/2023-10-04-bomb-lab.png +++ b/Resources/images/opengraph/posts/2023-10-04-bomb-lab.png diff --git a/Resources/images/opengraph/posts/2023-10-05-attack-lab.png b/Resources/images/opengraph/posts/2023-10-05-attack-lab.png Binary files differindex d55fc80..2097209 100644 --- a/Resources/images/opengraph/posts/2023-10-05-attack-lab.png +++ b/Resources/images/opengraph/posts/2023-10-05-attack-lab.png 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 Binary files differindex 7b44d6c..91e8370 100644 --- 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 diff --git a/docs/DallE3Base/posts/2023-10-04-bomb-lab.png b/docs/DallE3Base/posts/2023-10-04-bomb-lab.png Binary files differnew file mode 100644 index 0000000..e022194 --- /dev/null +++ b/docs/DallE3Base/posts/2023-10-04-bomb-lab.png diff --git a/docs/DallE3Base/posts/2023-10-05-attack-lab.png b/docs/DallE3Base/posts/2023-10-05-attack-lab.png Binary files differnew file mode 100644 index 0000000..aa4deae --- /dev/null +++ b/docs/DallE3Base/posts/2023-10-05-attack-lab.png 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 Binary files differnew file mode 100644 index 0000000..320d583 --- /dev/null +++ b/docs/DallE3Base/posts/2023-10-22-search-by-flair-reddit.png 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 @@ <title>Navan's Archive</title> <description>Rare Tips, Tricks and Posts</description> <link>https://web.navan.dev/</link><language>en</language> - <lastBuildDate>Sun, 22 Oct 2023 19:29:39 -0000</lastBuildDate> - <pubDate>Sun, 22 Oct 2023 19:29:39 -0000</pubDate> + <lastBuildDate>Sun, 22 Oct 2023 21:26:58 -0000</lastBuildDate> + <pubDate>Sun, 22 Oct 2023 21:26:58 -0000</pubDate> <ttl>250</ttl> <atom:link href="https://web.navan.dev/feed.rss" rel="self" type="application/rss+xml"/> diff --git a/docs/images/opengraph/posts/2023-10-04-bomb-lab.png b/docs/images/opengraph/posts/2023-10-04-bomb-lab.png Binary files differindex 3453c2a..551900e 100644 --- a/docs/images/opengraph/posts/2023-10-04-bomb-lab.png +++ b/docs/images/opengraph/posts/2023-10-04-bomb-lab.png diff --git a/docs/images/opengraph/posts/2023-10-05-attack-lab.png b/docs/images/opengraph/posts/2023-10-05-attack-lab.png Binary files differindex d55fc80..2097209 100644 --- a/docs/images/opengraph/posts/2023-10-05-attack-lab.png +++ b/docs/images/opengraph/posts/2023-10-05-attack-lab.png 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 Binary files differindex 7b44d6c..91e8370 100644 --- 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 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) |