Skip to content

Instantly share code, notes, and snippets.

@ryu22e
Last active August 29, 2015 13:57
Show Gist options
  • Save ryu22e/9367159 to your computer and use it in GitHub Desktop.
Save ryu22e/9367159 to your computer and use it in GitHub Desktop.
hell_yes
#!/usr/bin/env python
import argparse
import os
import sys
from PIL import Image, ImageFont, ImageDraw
if __name__ == '__main__':
# argparse
parser = argparse.ArgumentParser(description='HELL YES!')
parser.add_argument('-i', '--input', required=True)
parser.add_argument('-o', '--output')
parser.add_argument('-s', '--show', action='store_true', default=False)
args = parser.parse_args()
# Open image and resize
file_path = args.input
if not os.path.exists(file_path):
sys.exit("{} is not found.".format(file_path))
image = Image.open(file_path)
basewidth = 600
wpercent = (basewidth / float(image.size[0]))
hsize = int((float(image.size[1]) * float(wpercent)))
image = image.resize((basewidth, hsize), Image.ANTIALIAS)
# Load font
draw = ImageDraw.Draw(image)
font = ImageFont.truetype('Archive.otf', 100)
# Draw text
TEXT = "HELL YES"
textsize = draw.textsize(TEXT, font=font)
top = int((image.size[0] - textsize[0]) / 2)
left = int((image.size[1] - textsize[1]) * 0.9)
draw.text((top, left), TEXT, font=font, fill='#ff0000')
if args.show:
image.show()
if args.output:
image.save(args.output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment