Mercurial > ift6266
comparison transformations/ttf2jpg.py @ 133:a4e5128ef2cb
Adapted ttf2jpg to get fonts in /Tmp/allfonts local folder
author | boulanni <nicolas_boulanger@hotmail.com> |
---|---|
date | Sat, 20 Feb 2010 02:07:29 -0500 |
parents | 9c45e0071b52 |
children |
comparison
equal
deleted
inserted
replaced
132:25b7c1f20949 | 133:a4e5128ef2cb |
---|---|
13 | 13 |
14 class ttf2jpg(): | 14 class ttf2jpg(): |
15 def __init__(self, font_file = ''): | 15 def __init__(self, font_file = ''): |
16 self.w = 32 | 16 self.w = 32 |
17 self.h = 32 | 17 self.h = 32 |
18 self.font_dir = '/data/lisa/data/ift6266h10/fonts/windows7/' | 18 self.font_dir = '/Tmp/allfonts/' |
19 self.font_file = font_file | 19 self.font_file = font_file |
20 self.image_dir = './images/' | 20 self.image_dir = './images/' |
21 self.pattern = '*.ttf' | 21 self.pattern = '*.ttf' |
22 self.char_list = [] | 22 self.char_list = [] |
23 for i in range(0,10): | 23 for i in range(0,10): |
24 self.char_list.append(chr(ord('0') + i) ) | 24 self.char_list.append(chr(ord('0') + i) ) |
25 for i in range(0,26): | 25 for i in range(0,26): |
26 self.char_list.append(chr(ord('A') + i) ) | 26 self.char_list.append(chr(ord('A') + i) ) |
27 for i in range(0,26): | 27 for i in range(0,26): |
28 self.char_list.append(chr(ord('a') + i) ) | 28 self.char_list.append(chr(ord('a') + i) ) |
29 files = os.listdir(self.font_dir) | |
30 self.font_files = fnmatch.filter(files, '*.ttf') + fnmatch.filter(files, '*.TTF') | |
29 | 31 |
30 # get font name | 32 # get font name |
31 def get_settings_names(self): | 33 def get_settings_names(self): |
32 return [self.font_file] | 34 return [self.font_file] |
33 | 35 |
40 else: | 42 else: |
41 image.show() | 43 image.show() |
42 | 44 |
43 # set a random font for character generation | 45 # set a random font for character generation |
44 def set_random_font(self): | 46 def set_random_font(self): |
45 files = os.listdir(self.font_dir) | 47 i = random.randint(0, len(self.font_files) - 1) |
46 font_files = fnmatch.filter(files, self.pattern) | 48 self.font_file = self.font_dir + self.font_files[i] |
47 i = random.randint(0, len(font_files) - 1) | |
48 self.font_file = self.font_dir + font_files[i] | |
49 | 49 |
50 # return a picture array of "text" with font "font_file" | 50 # return a picture array of "text" with font "font_file" |
51 def create_image(self, text): | 51 def create_image(self, text): |
52 # create a w x h black picture, and a drawing space | 52 # create a w x h black picture, and a drawing space |
53 image = Image.new('L', (self.w, self.h), 'Black') | 53 image = Image.new('L', (self.w, self.h), 'Black') |