Example #1
0
 def drawer(image, text):
     draw = Draw(image)
     char_images = []
     for c in text:
         font = random.choice(fonts)
         c_width, c_height = draw.textsize(c, font=font)
         char_image = Image.new('RGB', (c_width, c_height), (0, 0, 0))
         char_draw = Draw(char_image)
         char_draw.text((0, 0), c, font=font, fill=color())
         char_image = char_image.crop(char_image.getbbox())
         for drawing in drawings:
             char_image = drawing(char_image)
         char_images.append(char_image)
     width, height = image.size
     offset = int((width - sum(int(i.size[0] * squeeze_factor)
                               for i in char_images[:-1]) -
                   char_images[-1].size[0]) / 2)
     for char_image in char_images:
         c_width, c_height = char_image.size
         mask = char_image.convert('L').point(lambda i: i * 1.97)
         image.paste(char_image,
                     (offset, int((height - c_height) / 2)),
                     mask)
         offset += int(c_width * squeeze_factor)
     return image
Example #2
0
 def drawer(image, text):
     width, height = image.size
     dx = width / 10
     width = width - dx
     dy = height / 10
     height = height - dy
     draw = Draw(image)
     for i in xrange(number):
         x = int(random.uniform(dx, width))
         y = int(random.uniform(dy, height))
         draw.line(((x, y), (x + level, y)), fill=color(), width=level)
     return image
Example #3
0
 def drawer(image, text):
     width, height = image.size
     dx = width / 10
     width = width - dx
     dy = height / 10
     height = height - dy
     draw = Draw(image)
     for i in xrange(number):
         x = int(random.uniform(dx, width))
         y = int(random.uniform(dy, height))
         draw.line(((x, y), (x + level, y)), fill=color(), width=level)
     return image
Example #4
0
 def drawer(image, text):
     dx, height = image.size
     dx = dx / number
     path = [(dx * i, random.randint(0, height))
             for i in range(1, number)]
     bcoefs = make_bezier(number - 1)
     points = []
     for coefs in bcoefs:
         points.append(tuple(sum([coef * p for coef, p in zip(coefs, ps)])
                             for ps in zip(*path)))
     draw = Draw(image)
     draw.line(points, fill=color(), width=width)
     return image
Example #5
0
 def drawer(image, text):
     dx, height = image.size
     dx = dx / number
     path = [(dx * i, random.randint(0, height)) for i in range(1, number)]
     bcoefs = make_bezier(number - 1)
     points = []
     for coefs in bcoefs:
         points.append(
             tuple(
                 sum([coef * p for coef, p in zip(coefs, ps)])
                 for ps in zip(*path)))
     draw = Draw(image)
     draw.line(points, fill=color(), width=width)
     return image
Example #6
0
 def drawer(image, text):
     draw = Draw(image)
     char_images = []
     for c in text:
         font = random.choice(fonts)
         c_width, c_height = draw.textsize(c, font=font)
         char_image = Image.new('RGB', (c_width, c_height), (0, 0, 0))
         char_draw = Draw(char_image)
         char_draw.text((0, 0), c, font=font, fill=color())
         char_image = char_image.crop(char_image.getbbox())
         for drawing in drawings:
             char_image = drawing(char_image)
         char_images.append(char_image)
     width, height = image.size
     offset = int(
         (width -
          sum(int(i.size[0] * squeeze_factor)
              for i in char_images[:-1]) - char_images[-1].size[0]) / 2)
     for char_image in char_images:
         c_width, c_height = char_image.size
         mask = char_image.convert('L').point(lambda i: i * 1.97)
         image.paste(char_image, (offset, int((height - c_height) / 2)),
                     mask)
         offset += int(c_width * squeeze_factor)
     return image
Example #7
0
 def drawer(image, text):
     Draw(image).rectangle([(0, 0), image.size], fill=color)
     return image