Added custom date for image
This commit is contained in:
parent
7ae706cf5f
commit
0cc9cc2813
16
main.py
16
main.py
|
@ -9,22 +9,19 @@ import urllib.request
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
version = 2.0
|
version = 2.1
|
||||||
style = False
|
style = False
|
||||||
|
|
||||||
text = "| V A P O R W A V E || G E N E R A T O R |"
|
text = "| V A P O R W A V E || G E N E R A T O R |"
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description=text)
|
parser = argparse.ArgumentParser(description=text)
|
||||||
parser.add_argument(
|
parser.add_argument("-M", "--music", help="generate v a p o r w a v e music", action="store_true")
|
||||||
"-M", "--music", help="generate v a p o r w a v e music", action="store_true"
|
parser.add_argument("-P", "--picture", help="generate VHS Style image", action="store_true")
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"-P", "--picture", help="generate VHS Style image", action="store_true"
|
|
||||||
)
|
|
||||||
parser.add_argument("-V", "--video", help="VHS Style Video", action="store_true")
|
parser.add_argument("-V", "--video", help="VHS Style Video", action="store_true")
|
||||||
parser.add_argument("-v", "--version", help="show program version", action="store_true")
|
parser.add_argument("-v", "--version", help="show program version", action="store_true")
|
||||||
parser.add_argument("-i", "--input")
|
parser.add_argument("-i", "--input")
|
||||||
parser.add_argument("-o", "--output", help="Output for specifying output video")
|
parser.add_argument("-o", "--output", help="Output for specifying output video")
|
||||||
|
parser.add_argument("-d","--date",help="Custom Date in yyyy/mm/dd format. e.g 2020/5/14")
|
||||||
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -32,6 +29,7 @@ args = parser.parse_args()
|
||||||
music = False
|
music = False
|
||||||
picture = False
|
picture = False
|
||||||
video = False
|
video = False
|
||||||
|
date = None
|
||||||
|
|
||||||
if args.version:
|
if args.version:
|
||||||
print("vaporwave generator 旺育栄", version)
|
print("vaporwave generator 旺育栄", version)
|
||||||
|
@ -46,6 +44,8 @@ if args.input:
|
||||||
query = args.input
|
query = args.input
|
||||||
if args.output:
|
if args.output:
|
||||||
outfile = args.output
|
outfile = args.output
|
||||||
|
if args.date:
|
||||||
|
date = args.date
|
||||||
else:
|
else:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
exit
|
exit
|
||||||
|
@ -180,6 +180,6 @@ if music:
|
||||||
name, title = download_file(query)
|
name, title = download_file(query)
|
||||||
gen_vapor(name, title)
|
gen_vapor(name, title)
|
||||||
elif picture:
|
elif picture:
|
||||||
generateVHSStyle(query, "out.jpg")
|
generateVHSStyle(query, "out.jpg",date=date)
|
||||||
elif video:
|
elif video:
|
||||||
VHS_Vid(query, outfile)
|
VHS_Vid(query, outfile)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import datetime
|
from datetime import datetime
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from PIL import ImageFont
|
from PIL import ImageFont
|
||||||
from PIL import ImageDraw
|
from PIL import ImageDraw
|
||||||
|
@ -98,8 +98,13 @@ def mod_image_repeat_rows(
|
||||||
img.save(out_name)
|
img.save(out_name)
|
||||||
|
|
||||||
|
|
||||||
def add_date(img_path, out_name="image.jpg", bottom_offset=0):
|
def add_date(img_path, out_name="image.jpg", bottom_offset=0,date=None,time=None):
|
||||||
date_obj = datetime.datetime.now()
|
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_1 = date_obj.strftime("%p %H:%M")
|
||||||
date_str_2 = date_obj.strftime("%b. %d %Y")
|
date_str_2 = date_obj.strftime("%b. %d %Y")
|
||||||
corner_offset = 50
|
corner_offset = 50
|
||||||
|
@ -150,7 +155,7 @@ if __name__ == "__main__":
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def generateVHSStyle(infile, outfile, silence=False):
|
def generateVHSStyle(infile, outfile, silence=False,date=None):
|
||||||
if silence:
|
if silence:
|
||||||
cut_rows = bool(random.getrandbits(1))
|
cut_rows = bool(random.getrandbits(1))
|
||||||
offset = random.choice([0, 5, 10])
|
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")
|
mod_image_repeat_rows("saturated.jpg", 0.012, 50, 10, True, "shifted.jpg")
|
||||||
else:
|
else:
|
||||||
mod_image_repeat_rows("saturated.jpg", 0, 0, 0, True, "shifted.jpg")
|
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)
|
add_date("noisy.jpg", outfile, bottom_offset=offset)
|
||||||
os.remove("shifted.jpg")
|
os.remove("shifted.jpg")
|
||||||
os.remove("saturated.jpg")
|
os.remove("saturated.jpg")
|
||||||
|
@ -176,7 +181,7 @@ def generateVHSStyle(infile, outfile, silence=False):
|
||||||
logger.info("Not applying lines effect")
|
logger.info("Not applying lines effect")
|
||||||
mod_image_repeat_rows("saturated.jpg", 0, 0, 0, True, "shifted.jpg")
|
mod_image_repeat_rows("saturated.jpg", 0, 0, 0, True, "shifted.jpg")
|
||||||
logger.info("Adding noise")
|
logger.info("Adding noise")
|
||||||
add_date("shifted.jpg", "noisy.jpg")
|
add_date("shifted.jpg", "noisy.jpg",date=date)
|
||||||
logger.info("Adding text")
|
logger.info("Adding text")
|
||||||
add_date("noisy.jpg", outfile, bottom_offset=offset)
|
add_date("noisy.jpg", outfile, bottom_offset=offset)
|
||||||
logger.info("Generated Image: out.jpg")
|
logger.info("Generated Image: out.jpg")
|
||||||
|
|
Loading…
Reference in New Issue