diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2020-08-19 12:21:15 +0530 |
---|---|---|
committer | Navan Chauhan <navanchauhan@gmail.com> | 2020-08-19 12:21:15 +0530 |
commit | 0cc9cc2813f9d630436677229e6f311403180a18 (patch) | |
tree | 7596b7e9f6ad306026b635dbfa3dde05ae60c2c7 /src/VHSImage.py | |
parent | 7ae706cf5fc20b43b5408a0ebf7f165660d73452 (diff) |
Added custom date for image
Diffstat (limited to 'src/VHSImage.py')
-rw-r--r-- | src/VHSImage.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/VHSImage.py b/src/VHSImage.py index fc21adc..ebf057f 100644 --- a/src/VHSImage.py +++ b/src/VHSImage.py @@ -1,4 +1,4 @@ -import datetime +from datetime import datetime from PIL import Image from PIL import ImageFont from PIL import ImageDraw @@ -98,10 +98,15 @@ def mod_image_repeat_rows( img.save(out_name) -def add_date(img_path, out_name="image.jpg", bottom_offset=0): - date_obj = datetime.datetime.now() - date_str_1 = date_obj.strftime("%p %H:%M") - date_str_2 = date_obj.strftime("%b. %d %Y") +def add_date(img_path, out_name="image.jpg", bottom_offset=0,date=None,time=None): + if date==None: + date_obj = datetime.now() + date_str_1 = date_obj.strftime("%p %H:%M") + date_str_2 = date_obj.strftime("%b. %d %Y") + else: + date_obj = datetime.strptime(date, '%Y/%m/%d') + date_str_1 = date_obj.strftime("%p %H:%M") + date_str_2 = date_obj.strftime("%b. %d %Y") corner_offset = 50 img = Image.open(img_path) _, height = img.size @@ -150,7 +155,7 @@ if __name__ == "__main__": """ -def generateVHSStyle(infile, outfile, silence=False): +def generateVHSStyle(infile, outfile, silence=False,date=None): if silence: cut_rows = bool(random.getrandbits(1)) offset = random.choice([0, 5, 10]) @@ -159,7 +164,7 @@ def generateVHSStyle(infile, outfile, silence=False): mod_image_repeat_rows("saturated.jpg", 0.012, 50, 10, True, "shifted.jpg") else: mod_image_repeat_rows("saturated.jpg", 0, 0, 0, True, "shifted.jpg") - add_date("shifted.jpg", "noisy.jpg") + add_date("shifted.jpg", "noisy.jpg",date=date) add_date("noisy.jpg", outfile, bottom_offset=offset) os.remove("shifted.jpg") os.remove("saturated.jpg") @@ -176,7 +181,7 @@ def generateVHSStyle(infile, outfile, silence=False): logger.info("Not applying lines effect") mod_image_repeat_rows("saturated.jpg", 0, 0, 0, True, "shifted.jpg") logger.info("Adding noise") - add_date("shifted.jpg", "noisy.jpg") + add_date("shifted.jpg", "noisy.jpg",date=date) logger.info("Adding text") add_date("noisy.jpg", outfile, bottom_offset=offset) logger.info("Generated Image: out.jpg") |