Created
September 9, 2011 21:53
-
-
Save sofferm/1207432 to your computer and use it in GitHub Desktop.
Python Image Processing, writing text on image
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
import Image | |
import ImageDraw | |
import ImageFont | |
# string according to dokuwiki syntax for a table row | |
data = "| # | 19.11.2011 | DARK TRANQUILLITY, ELUVEITIE, VARG, MERCENARY, GURD, OMNIUM GATHERUM | FZW, Dortmund |" | |
# first band of the line up (to constrain text length) | |
subject = data.split("|")[3].split(',')[0].strip() | |
date = data.split("|")[2].strip() | |
location = data.split("|")[4].strip() | |
imageTemplate = "sig-patch-festivals-template.png" | |
imageOutput = "sig.png" | |
fill="#b7b7b7" | |
fontFile = "/usr/share/fonts/truetype/ttf-liberation/LiberationSans-Bold.ttf" | |
font = ImageFont.truetype(fontFile, 10) | |
y = 20 | |
yn = 13 | |
centerX = 218 | |
subjectX = centerX - (font.getsize(subject)[0]/2) | |
dateX = centerX - (font.getsize(date)[0]/2) | |
locationX = centerX - (font.getsize(location)[0]/2) | |
im = Image.open(imageTemplate) | |
draw = ImageDraw.Draw(im) | |
draw.text((subjectX, y), subject, font=font, fill=fill) | |
draw.text((dateX, y+yn), date, font=font, fill=fill) | |
draw.text((locationX, y+2*yn), location, font=font, fill=fill) | |
del draw | |
im.save(imageOutput, "PNG") | |
with open(imageOutput, 'r') as f: | |
import ftplib | |
ftp = ftplib.FTP('www.st3fan.de', 'secretname', 'evenmoresecret') | |
ftp.cwd('www.st3fan.de') | |
ftp.cwd('img') | |
ftp.storbinary('STOR %s' % imageOutput, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment