#!/usr/bin/env python ## # Author: IL'dar AKHmetgaleev aka AkhIL # e-mail: akhilman at gmail dot com # web: http://akhil.nm.ru # # This code is licensed under # Creative Commons Attribution 3.0 Unported License # http://creativecommons.org/licenses/by/3.0/ ## fontname = "/usr/share/fonts/TrueType/tahoma.ttf" import Image,ImageDraw,ImageFont,ImageOps from random import random import sys if len (sys.argv) != 3: sys.stdout.write("""\ Usage: %s text imagename.ext """ % sys.argv[0]) sys.exit() text = sys.argv[1] size = ((len(text)+1)*20,60) fg = Image.new('L',size) bg = Image.new('RGB',size) draw = ImageDraw.Draw(bg) def randomcolor(): c = [random(),random(),random()] l = max(c) c = map(lambda x: int(x/l * 255),c) return tuple(c) for n in range(size[0]/2): x = random()*size[0] y = random()*size[1] s = size[1]*0.1 + random()*size[1]*0.2 draw.ellipse( ( x-s, y-s, x+s, y+s ), fill=randomcolor()) del (draw) draw = ImageDraw.Draw(fg) for n in range(len(text)): char = text[n] font = ImageFont.truetype(fontname,int(20+random()*20)) x = n * (size[0] / len(text) ) + random() * (size[0] / len(text)) * 0.2 y = random() * size[1] * 0.4 draw.text((x,y),char,font=font,\ fill=255) img = bg.copy() bg = ImageOps.invert(bg) img = Image.composite(img,bg,fg) #img.show() img.save(sys.argv[2])