--- a/index.cgi Tue May 05 17:18:04 2009 +0300
+++ b/index.cgi Tue May 05 17:23:40 2009 +0300
@@ -5,9 +5,25 @@
from PIL import Image, ImageDraw, ImageFont, ImageEnhance
from cStringIO import StringIO
-import random
+import random, itertools
-
+if not hasattr(itertools, 'izip_longest') :
+
+ def izip_longest(*args, **kwds):
+ # izip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-
+ fillvalue = kwds.get('fillvalue')
+ def sentinel(counter = ([fillvalue]*(len(args)-1)).pop):
+ yield counter() # yields the fillvalue, or raises IndexError
+ fillers = itertools.repeat(fillvalue)
+ iters = [itertools.chain(it, sentinel(), fillers) for it in args]
+ try:
+ for tup in itertools.izip(*iters):
+ yield tup
+ except IndexError:
+ pass
+
+ itertools.izip_longest = izip_longest
+
class Defaults :
# settings
text = [
@@ -66,16 +82,24 @@
data = []
- for line, char, color in zip(text, chars, line_colors) :
+ for line, char, color in itertools.izip_longest(text, chars, line_colors, fillvalue=None) :
# pick position to place char
pos = random.randint(1, len(line) - 1)
+
+ if not color :
+ color = "#000000"
# split into three parts
- data.append([
- (line[:pos], "#000000"),
- (char, color),
- (line[pos:], "#000000"),
- ])
+ if char :
+ data.append([
+ (line[:pos], "#000000"),
+ (char, color),
+ (line[pos:], "#000000"),
+ ])
+ else :
+ data.append([
+ (line, "#000000"),
+ ])
return data