Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added data/opengenus_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions formats/format1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from manipulation import *
from meme_generator import *

class Format1:

Expand Down
43 changes: 35 additions & 8 deletions meme_generator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
########################
#### MEME GENERATOR ####
########################

# This service contains procedure to generate memes

import argparse as arg
import os
import random
Expand All @@ -10,19 +16,34 @@
import urllib.request
import logo

# This procedure uses formatObj to generate and show meme
def use(formatObj):
meme_img = formatObj.generate()
meme_with_logo = add_logo(meme_img)
meme_with_logo.save(meme_with_logo.filename)
meme_with_logo.show()


# Adds logo image and text to a meme
def add_logo(img):
img = add_logo_img(img, 'data/OpenGenus.png')
img = add_logo_txt(img, 'OpenGenus')
return img


<<<<<<< master
def add_logo_opaque(image):
logo = Image.open('opengenus_logo.png')
size= logo.size
nimg = logo.resize((int(size[0]/4),int(size[1]/4)))
n=image.size
k=int((n[0]-int(size[0]/4)))
g=int((n[1]-int(size[1]/4)))
image.paste(nimg, ((k),(g)))
return image


=======
# Procedure for adding logo image
>>>>>>> master
def add_logo_img(meme_img, logo_img_path):
logo_img = Image.open(logo_img_path)
w, h = logo_img.size
Expand All @@ -37,7 +58,7 @@ def add_logo_img(meme_img, logo_img_path):
meme_logo.filename = meme_img.filename[:-4]+'.png'
return meme_logo


# Procedure for adding logo text
def add_logo_txt(meme_logo, txt):
meme_logo_opengenus = Image.new('RGBA', meme_logo.size, (255, 255, 255, 0))
fnt = ImageFont.truetype('./impact/impact.ttf', 20)
Expand All @@ -49,29 +70,33 @@ def add_logo_txt(meme_logo, txt):
out_img.filename = meme_logo.filename
return out_img


# Utility function to download image from an address (URL)
def download(url, img_name):
urllib.request.urlretrieve(url, img_name+".jpg")

# Generates random meme.

def random_meme(show='True'):
with open('index.json') as f:
data = json.load(f)
num_of_images = len(data['data'])

if show == 'True':
if show == 'True': # When show flag is set, the generated image is shown
random_idx = random.randint(1, num_of_images)
folder = data['data'][random_idx]['location']
Image.open(folder).show()
else:
else: # When show flag is not set, Information about meme is printed
print (data['data'][random.randint(1,
num_of_images)]['description'])


# Main Function

# End point of this service
def start(args):
'''
Generates meme with different arrangement of text and image based on arguments.
# Mode - 0, 1
# Formats
'''
formatObj = None
if args.mode == '0':
if args.format == '0':
Expand Down Expand Up @@ -356,3 +381,5 @@ def start(args):
top_text=top_text,
bottom_text=bottom_text)
use(formatobj)

# Calls use function to generate and show images corresponging to formatObj generated