Skip to content

Instantly share code, notes, and snippets.

@nvbn
Created September 14, 2015 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nvbn/03621f669965d4b9d57f to your computer and use it in GitHub Desktop.
Save nvbn/03621f669965d4b9d57f to your computer and use it in GitHub Desktop.
python 3.5 matrix multiplication operator in use
from io import BytesIO
from PIL import Image, ImageDraw, ImageFont
import requests
def get_x(img, draw, font, text):
img_w, _ = img.size
text_w, _ = draw.textsize(text, font=font)
return int((img_w - text_w) / 2)
def draw_caption(img, text, y):
font = ImageFont.truetype('arial', 60)
draw = ImageDraw.Draw(img)
x = get_x(img, draw, font, text)
for border_x in range(x - 2, x + 3):
for border_y in range(y - 2, y + 3):
draw.text((border_x, border_y), text, font=font, fill='black')
draw.text((x, y), text, font=font)
def get_background():
response = requests.get(
'http://i2.kym-cdn.com/photos/images/newsfeed/000/279/114/7ff.jpg',
stream=True)
bg_file = BytesIO(response.raw.read())
return Image.open(bg_file)
class Meme:
def __init__(self, text):
self.text = text
def __matmul__(self, other):
img = get_background()
draw_caption(img, self.text, 20)
draw_caption(img, other.text, 320)
img.show()
воруй = Meme('воруй')
убивай = Meme('убивай')
воруй@убивай
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment