diff options
| -rw-r--r-- | Resources/DallE3Base/posts/2023-10-04-bomb-lab.png | bin | 0 -> 1720442 bytes | |||
| -rw-r--r-- | Resources/DallE3Base/posts/2023-10-05-attack-lab.png | bin | 0 -> 1702606 bytes | |||
| -rw-r--r-- | Resources/DallE3Base/posts/2023-10-22-search-by-flair-reddit.png | bin | 0 -> 2202291 bytes | |||
| -rw-r--r-- | Resources/images/opengraph/posts/2023-10-04-bomb-lab.png | bin | 18697 -> 692994 bytes | |||
| -rw-r--r-- | Resources/images/opengraph/posts/2023-10-05-attack-lab.png | bin | 2855252 -> 695415 bytes | |||
| -rw-r--r-- | Resources/images/opengraph/posts/2023-10-22-search-by-flair-reddit.png | bin | 23362 -> 854300 bytes | |||
| -rw-r--r-- | generate_me.py | 96 | ||||
| -rw-r--r-- | helper_libs/image_utils.py | 9 | 
8 files changed, 70 insertions, 35 deletions
| diff --git a/Resources/DallE3Base/posts/2023-10-04-bomb-lab.png b/Resources/DallE3Base/posts/2023-10-04-bomb-lab.pngBinary files differ new 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.pngBinary files differ new 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.pngBinary files differ new 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.pngBinary files differ index 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.pngBinary files differ index 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.pngBinary files differ index 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/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) | 
