diff 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
line wrap: on
line diff
--- a/transformations/ttf2jpg.py	Sat Feb 20 02:06:38 2010 -0500
+++ b/transformations/ttf2jpg.py	Sat Feb 20 02:07:29 2010 -0500
@@ -15,7 +15,7 @@
     def __init__(self, font_file = ''):
         self.w = 32
         self.h = 32
-        self.font_dir = '/data/lisa/data/ift6266h10/fonts/windows7/'
+        self.font_dir = '/Tmp/allfonts/'
         self.font_file = font_file
         self.image_dir = './images/'
         self.pattern = '*.ttf'
@@ -26,6 +26,8 @@
             self.char_list.append(chr(ord('A') + i) )
         for i in range(0,26):
             self.char_list.append(chr(ord('a') + i) )
+        files = os.listdir(self.font_dir)
+        self.font_files = fnmatch.filter(files, '*.ttf') + fnmatch.filter(files, '*.TTF')
 
     # get font name
     def get_settings_names(self):
@@ -42,10 +44,8 @@
 
     # set a random font for character generation
     def set_random_font(self):
-        files = os.listdir(self.font_dir)
-        font_files = fnmatch.filter(files, self.pattern)
-        i = random.randint(0, len(font_files) - 1)
-        self.font_file = self.font_dir + font_files[i]
+        i = random.randint(0, len(self.font_files) - 1)
+        self.font_file = self.font_dir + self.font_files[i]
 
     # return a picture array of "text" with font "font_file"
     def create_image(self, text):