forked from lnus/memegen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memegen.py
49 lines (42 loc) · 1.94 KB
/
memegen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import textwrap
from PIL import Image, ImageDraw, ImageFont
class memeGen():
def generate(self, top, bot, image, **kwargs):
#Opens up your SPICY MEME TEMPLATE
im = Image.open(image)
#Resizes the image for perfect MEME size
im = im.resize((500, 500), Image.ANTIALIAS)
#Stupid fucking useless arguments
self.output = "output.png"
self.font = ImageFont.truetype("impact.ttf", 60)
self.stroke = "black"
self.textcolor = "white"
self.thickness = 3
width, height = im.size
draw = ImageDraw.Draw(im)
topH, topP = 0, 10
botH, botP = 420, 10
pTop = textwrap.wrap(top, width=15)
pBot = textwrap.wrap(bot, width=15)
#Sets up the keyword arguments if you want proper CUSTOMIZATION
for key, value in kwargs.items():
setattr(self, key, value)
#Writes the text with a spicy meme outline
for line in pTop:
w, h = draw.textsize(line, font=self.font)
draw.text((((width - w)/2)-self.thickness, topH), top, font=self.font, fill=self.stroke)
draw.text((((width - w)/2)+self.thickness, topH), top, font=self.font, fill=self.stroke)
draw.text((((width - w)/2), topH-self.thickness), top, font=self.font, fill=self.stroke)
draw.text((((width - w)/2), topH+self.thickness), top, font=self.font, fill=self.stroke)
draw.text(((width - w)/2, topH), top, font=self.font, fill=self.textcolor)
topH += h + topP
for line in pBot:
w, h = draw.textsize(line, font=self.font)
draw.text((((width - w)/2)-self.thickness, botH), bot, font=self.font, fill=self.stroke)
draw.text((((width - w)/2)+self.thickness, botH), bot, font=self.font, fill=self.stroke)
draw.text((((width - w)/2), botH-self.thickness), bot, font=self.font, fill=self.stroke)
draw.text((((width - w)/2), botH+self.thickness), bot, font=self.font, fill=self.stroke)
draw.text(((width - w)/2, botH), bot, font=self.font, fill=self.textcolor)
botH += h + botP
#saves the dank meme
im.save(self.output)