Mercurial > ift6266
diff data_generation/transformations/pycaptcha/Captcha/Visual/Text.py @ 184:81f8466dc121
Transient exception handling in captchas (ie. lorsque le NFS est temporairement inaccessible)
author | boulanni <nicolas_boulanger@hotmail.com> |
---|---|
date | Sat, 27 Feb 2010 19:26:26 -0500 |
parents | 1f5937e9e530 |
children |
line wrap: on
line diff
--- a/data_generation/transformations/pycaptcha/Captcha/Visual/Text.py Sat Feb 27 19:21:57 2010 -0500 +++ b/data_generation/transformations/pycaptcha/Captcha/Visual/Text.py Sat Feb 27 19:26:26 2010 -0500 @@ -39,7 +39,7 @@ return (fileName, size) # Predefined font factories -defaultFontFactory = FontFactory(25, "allfonts") +defaultFontFactory = FontFactory(25, "/Tmp/allfonts") #defaultFontFactory = FontFactory((30, 40), "vera") class TextLayer(Visual.Layer): @@ -77,7 +77,17 @@ self.borderColor = borderColor def render(self, img): - font = ImageFont.truetype(*self.font) + + i=1 + while True: + try: + font = ImageFont.truetype(*self.font) + break + except: + print "try#", i, self.font + i += 1 + if i>10: raise + textSize = font.getsize(self.text) draw = ImageDraw.Draw(img)