comparison transformations/ttf2jpg.py @ 109:9c45e0071b52

Adapté le générateur d'images de fontes pour utiliser en amont du pipeline
author boulanni <nicolas_boulanger@hotmail.com>
date Tue, 16 Feb 2010 13:10:06 -0500
parents 05145f4fb609
children a4e5128ef2cb
comparison
equal deleted inserted replaced
108:a7cd8dd3221c 109:9c45e0071b52
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 = '/usr/share/fonts/truetype/ttf-liberation/' 18 self.font_dir = '/data/lisa/data/ift6266h10/fonts/windows7/'
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):
24 self.char_list.append(chr(ord('0') + i) )
25 for i in range(0,26):
26 self.char_list.append(chr(ord('A') + i) )
23 for i in range(0,26): 27 for i in range(0,26):
24 self.char_list.append(chr(ord('a') + i) ) 28 self.char_list.append(chr(ord('a') + i) )
25 for i in range(0,26):
26 self.char_list.append(chr(ord('A') + i) )
27 for i in range(0,10):
28 self.char_list.append(chr(ord('0') + i) )
29 29
30 # get font name 30 # get font name
31 def get_settings_names(self): 31 def get_settings_names(self):
32 return [self.font_file] 32 return [self.font_file]
33 33
83 83
84 # generate random character from random font file as a numpy array 84 # generate random character from random font file as a numpy array
85 def generate_image(self): 85 def generate_image(self):
86 self.set_random_font() 86 self.set_random_font()
87 i = random.randint(0, len(self.char_list) - 1) 87 i = random.randint(0, len(self.char_list) - 1)
88 return self.generate_image_from_char(self.char_list[i]) 88 return self.generate_image_from_char(self.char_list[i]), i
89 89
90 # test method, create character images for all fonts in "font_dir" in dir "image_dir" 90 # test method, create character images for all fonts in "font_dir" in dir "image_dir"
91 def test(self): 91 def test(self):
92 import time 92 import time
93 93
115 115
116 if __name__ == '__main__': 116 if __name__ == '__main__':
117 117
118 myttf2jpg = ttf2jpg() 118 myttf2jpg = ttf2jpg()
119 #myttf2jpg.test() 119 #myttf2jpg.test()
120 image = myttf2jpg.generate_image() 120 image, i = myttf2jpg.generate_image()
121 myttf2jpg.save_image(image, '') 121 myttf2jpg.save_image(image, '')