# ab.py : draw superimposed letters a la some works by Tauba Auerbach # Usage: # python ab.py # view *.png # Actually, do this several times. For each font, create two images: one # with all of the upper-case letters, one with all of the lower-case letters. import glob # list all font files import os # useful to get the "Foo.ttf" out of "/path/to/Foo.ttf" import Image # Python Imaging Library import ImageDraw # We want to scribble on an image import ImageFont # ...using text. IMAGE_WIDTH = 600 IMAGE_HEIGHT = 600 FONT_SIZE = 400 l_alphabet = 'abcdefghijklmnopqrstuvwxyz' u_alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' # On my system, fonts live under the directory /var/lib/defoma/fontconfig.d/ # Get a list of them: font_list = glob.glob('/var/lib/defoma/fontconfig.d/*/*') for font_name in font_list: suffix = font_name[-3:] if not suffix in ('ttf', 'pfa', 'pfb'): continue # Skip these font files, I can't get them to work: if font_name.find('Thryo') > -1: continue # crash if font_name.find('CharterBT') > -1: continue # crash if font_name.find('Dingbats.pfb') > -1: continue # blank if font_name.find('StandardSymL.pfb') > -1: continue # blank i = Image.new("RGB", (IMAGE_WIDTH, IMAGE_HEIGHT), 'white') d = ImageDraw.Draw(i) f = ImageFont.truetype(font_name, FONT_SIZE) for c in l_alphabet: s = ' ' + c + ' ' # workaround errors drawing outside bounding box (s_width, s_height) = d.textsize(s, font=f) d.text(((IMAGE_WIDTH - s_width)/2, 0), s, fill='black', font=f) # The following cryptic line takes a font filename like # /var/lib/defoma/fontconfig.d/U/Utopia-BoldItalic.pfa # and uses the "interesting parts" to get # Utopia-BoldItalic_pfa_l.png out_name = os.path.split(font_name)[-1].replace('.', '_') + '_l.png' i.save(out_name) i = Image.new("RGB", (IMAGE_WIDTH, IMAGE_HEIGHT), 'white') d = ImageDraw.Draw(i) f = ImageFont.truetype(font_name, FONT_SIZE) for c in u_alphabet: s = ' ' + c + ' ' # workaround errors drawing outside bounding box (s_width, s_height) = d.textsize(s, font=f) d.text(((IMAGE_WIDTH - s_width)/2, 0), s, fill='black', font=f) out_name = os.path.split(font_name)[-1].replace('.', '_') + '_u.png' i.save(out_name)