Created
October 13, 2012 16:41
-
-
Save petrushev/3885291 to your computer and use it in GitHub Desktop.
Create custom `mudrecot` meme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""Create custom `mudrecot` meme""" | |
import PIL | |
from PIL import ImageFont | |
from PIL import Image | |
from PIL import ImageDraw | |
font_path = "/usr/share/fonts/TTF/LiberationSans-Bold.ttf" | |
text_color = (117, 44, 29) | |
bkg_color = (214,214,214) | |
img_kolozov = Image.open('kolozov.jpg') | |
def main(path, text): | |
img_src = Image.open(path) | |
x, y = img_src.size | |
x, y = x * img_kolozov.size[0]/ y, img_kolozov.size[1] | |
img_src = img_src.resize((x,y)) | |
img = Image.new("RGBA", (img_kolozov.size[0] + x + 40 , img_kolozov.size[0] + 200), bkg_color) | |
draw = ImageDraw.Draw(img) | |
img.paste(img_src, (10,10,x+10,y+10)) | |
img.paste(img_kolozov, (x+30, 10, x+30+img_kolozov.size[0], y+10)) | |
font_size = int(img_src.size[0] *1.0/ max([len(text[0]), len(text[1])]) * 1.9) | |
font = ImageFont.truetype(font_path, font_size) | |
draw.text((10, y + 20), text[0], text_color, font=font) | |
draw.text((10, y + 20 + font_size + 3), text[1], text_color, font=font) | |
font_size = int(img_kolozov.size[0] *1.0/ max([len(text[3]), len(text[2])]) * 1.4) | |
font = ImageFont.truetype(font_path, font_size) | |
draw.text((x+30, y + 20), text[2], text_color, font=font) | |
draw.text((x+30, y + 20 + font_size + 3), text[3], text_color, font=font) | |
img.save("mudrec.png") | |
if __name__=='__main__': | |
main(path="debt.jpg", | |
text = [u'Човек станува роб во ситуации', u'од кои во друг случај би бил мртов', | |
u'Поарно в гроб', u'отколку роб'] ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment