Skip to content

Instantly share code, notes, and snippets.

@mrchrisadams
Created March 5, 2009 11:57
Show Gist options
  • Save mrchrisadams/74326 to your computer and use it in GitHub Desktop.
Save mrchrisadams/74326 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# encoding: utf-8
"""
makewidget.py
Created by Chris Adams on 2009-03-03.
"""
from PIL import Image, ImageFont, ImageDraw
import sys
import os
def main():
# open image to serve as background
pic = Image.open('blank_badge.png')
# set font with to convert Truetype file:
font = ImageFont.truetype("DIN-Bold.ttf", 36)
# convenience variable
textcopy = ImageDraw.Draw(pic)
# add fontmode should turn anti aliasing on.
textcopy.fontmode="0"
# start adding copy line by line to simulate
# line wrapping
textcopy.text((20, 25), "Ugly", font=font, fill=50)
textcopy.text((20, 85), "Aliasing", font=font, fill=55)
textcopy.text((20, 145), "Fixed?", font=font, fill=59)
# finally display image and save locally
pic.save('PIL-generated-fontmode.png')
pic.show()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment