Skip to content
124 changes: 75 additions & 49 deletions meme_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

parser = arg.ArgumentParser('Meme Generator')

parser.add_argument('--mode', default=0, help='Choose from two modes: 0-Command line 1-Interactive 2-URL')
parser.add_argument('--mode', default=1, help='Choose from two modes: 0-Command line 1-Interactive 2-URL')

parser.add_argument('--url1', default=None, help='Enter URL for first image')
parser.add_argument('--url2', default=None, help='Enter URL for second image')
parser.add_argument('--format', default=None, help='Enter the format type')
parser.add_argument('--url1', default='https://www.pexels.com/photo/cute-toy-outdoors-owl-34533/', help='Enter URL for first image')
parser.add_argument('--url2', default='https://www.pexels.com/photo/close-up-photography-of-owl-1543417/', help='Enter URL for second image')
parser.add_argument('--format', default=1, help='Enter the format type')
parser.add_argument('--image1', type=str, default=None, help='Enter the image path for 1st image')
parser.add_argument('--image2', type=str, default=None, help='Enter the image path for 2nd image')
parser.add_argument('--text1', type=str, default=None, help='Enter text1')
Expand Down Expand Up @@ -44,53 +44,79 @@ def random_meme(show='True'):
print (data['data'][random.randint(1,
num_of_images)]['description'])


# Main Function

if __name__ == '__main__':
if args.mode == '0':
if args.format == '0':
if args.random == 'True' or args.random == 'False':
random_meme(args.random)
else:
print ('Empty or invalid arguments')

if args.format == '1':
if args.image1 is not None and args.text1 is not None:
preprocessImages(args.image1)
formatObj = Format1(args.image1, args.text1)
formatObj.generate()
else:
print ('Missing arguments')
#checking argument
def checkarg(format):
if format=='1' or format=='2':
if args.image1 is None and args.text1 is None:
print("image1 and text1 is missing!!!")
return False
elif args.image1 is None:
print("image1 is missing!!!")
return False
elif args.text1 is None:
print("text1 is missing!!!")
return False
else:
return True
elif format=='3':
if args.image1 is None or args.text1 is None or args.text2 is None:
if args.image1 is None:
print("Image is Missing!!")
return False
if args.text1 is None:
print("Text 1 is Missing!!")
return False
if args.text2 is None:
print("Text 2 is Missing!!")
return False
else:
return True

elif format=='4':
if args.image1 is None or args.image2 is None or args.text1 is None or args.text2 is None:
if args.image1 is None:
print("Image 1 is Missing!!")
if args.image2 is None:
print("Image 2 is Missing!!")
if args.text1 is None:
print("Text 1 is Missing!!")
if args.text2 is None:
print("Text 2 is Missing!!")
else:
return True

if args.format == '2':
if args.image1 is not None and args.text1 is not None:
preprocessImages(args.image1)
formatObj = Format2(args.image1, args.text1)
formatObj.generate()
else:
print ('Missing arguments')

if args.format == '3':
if args.image1 is not None and args.text1 is not None \
and args.text2 is not None:
preprocessImages(args.image1)
formatObj = Format3(args.image1, args.text1, args.text2)
formatObj.generate()
else:
print ('Missing arguments')

if args.format == '4':
if args.image1 is not None and args.text1 is not None \
and args.image2 is not None and args.text2 is not None:
preprocessImages(args.image1)
preprocessImages(args.image2)
formatObj = Format4(args.image1, args.image2, args.text1, args.text2)
formatObj.generate()
else:
print ('Missing arguments')
#Main Function

if __name__ == '__main__':
if args.mode == '0':
if checkarg(args.format) is True:
if args.format == '0':
if args.random == 'True' or args.random == 'False':
random_meme(args.random)
else:
print ('Empty or invalid arguments')
if args.format == '1':
preprocessImages(args.image1)
formatObj = Format1(args.image1, args.text1)
formatObj.generate()
if args.format == '2':
preprocessImages(args.image1)
formatObj = Format1(args.image1, args.text1)
formatObj.generate()
if args.format == '3':
preprocessImages(args.image1)
formatObj = Format3(args.image1, args.text1, args.text2)
formatObj.generate()
if args.format == '4':
preprocessImages(args.image1)
preprocessImages(args.image2)
formatObj = Format4(args.image1, args.image2, args.text1, args.text2)
formatObj.generate()

if args.mode == '1':
if args.format is None:
checkarg(args.format)
if args.format is not None:
format = args.format
else:
Expand Down Expand Up @@ -145,8 +171,7 @@ def random_meme(show='True'):
if format == '1':
if args.url1 is not None:
url = args.url1
else:
url = input('Enter image URL: ')
url = input('Enter image URL: ')
download(url, 'meme_img')
img = 'meme_img.jpg'
top_text = input('Input the top line here: ')
Expand Down Expand Up @@ -198,3 +223,4 @@ def random_meme(show='True'):
preprocessImages(img2)
formatObj = Format4(img1, img2, top_text, bottom_text)
formatObj.generate()
formatObj.generate()