Exemplo n.º 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
Exemplo n.º 2
0
 def drawer(image):
     width, height = image.size
     dx = int(random.random() * width * dx_factor)
     dy = int(random.random() * height * dy_factor)
     image2 = Image.new('RGB', (width + dx, height + dy))
     image2.paste(image, (dx, dy))
     return image2
Exemplo n.º 3
0
 def drawer(image):
     width, height = image.size
     dx = int(random.random() * width * dx_factor)
     dy = int(random.random() * height * dy_factor)
     image2 = Image.new('RGB', (width + dx, height + dy))
     image2.paste(image, (dx, dy))
     return image2
Exemplo n.º 4
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
Exemplo n.º 5
0
 def drawer(image):
     width, height = image.size
     dx = width * dx_factor
     dy = height * dy_factor
     x1 = int(random.uniform(-dx, dx))
     y1 = int(random.uniform(-dy, dy))
     x2 = int(random.uniform(-dx, dx))
     y2 = int(random.uniform(-dy, dy))
     image2 = Image.new(
         'RGB', (width + abs(x1) + abs(x2), height + abs(y1) + abs(y2)))
     image2.paste(image, (abs(x1), abs(y1)))
     width2, height2 = image2.size
     return image2.transform((width, height), Image.QUAD,
                             (x1, y1, -x1, height2 - y2, width2 + x2,
                              height2 + y2, width2 - x2, -y1))
Exemplo n.º 6
0
 def drawer(image):
     width, height = image.size
     dx = width * dx_factor
     dy = height * dy_factor
     x1 = int(random.uniform(-dx, dx))
     y1 = int(random.uniform(-dy, dy))
     x2 = int(random.uniform(-dx, dx))
     y2 = int(random.uniform(-dy, dy))
     image2 = Image.new('RGB',
                        (width + abs(x1) + abs(x2),
                         height + abs(y1) + abs(y2)))
     image2.paste(image, (abs(x1), abs(y1)))
     width2, height2 = image2.size
     return image2.transform(
         (width, height), Image.QUAD,
         (x1, y1,
          -x1, height2 - y2,
          width2 + x2, height2 + y2,
          width2 - x2, -y1))
Exemplo n.º 7
0
 def render(text):
     image = Image.new('RGB', (width, height), (255, 255, 255))
     for drawing in drawings:
         image = drawing(image, text)
         assert image
     return image
Exemplo n.º 8
0
 def render(text):
     image = Image.new('RGB', (width, height), (255, 255, 255))
     for drawing in drawings:
         image = drawing(image, text)
         assert image
     return image