Example #1
0
 def execute(self, image, query):
     athor = get_image_object(self.image, self.storage)
     x2, y2 = athor.size
     x1 = get_coords(image.size[0], athor.size[0], self.x)
     y1 = get_coords(image.size[1], athor.size[1], self.y)
     box = (
         x1,
         y1,
         x1 + x2,
         y1 + y2,
     )
     # Note that if you paste an "RGBA" image, the alpha band is ignored.
     # You can work around this by using the same image as both source image and mask.
     image = image.copy()
     if athor.mode == 'RGBA':
         if image.mode == 'RGBA':
             channels = image.split()
             alpha = channels[3]
             image = Image.merge('RGB', channels[0:3])
             athor_channels = athor.split()
             athor_alpha = athor_channels[3]
             athor = Image.merge('RGB', athor_channels[0:3])
             image.paste(athor, box, mask=athor_alpha)
             # merge alpha
             athor_image_alpha = Image.new('L', image.size, color=0)
             athor_image_alpha.paste(athor_alpha, box)
             new_alpha = ImageChops.add(alpha, athor_image_alpha)
             image = Image.merge('RGBA', image.split() + (new_alpha, ))
         else:
             image.paste(athor, box, mask=athor)
     else:
         image.paste(athor, box)
     return image
 def execute(self, image, query):
     athor = get_image_object(self.image, self.storage)
     x2, y2 = athor.size
     x1 = get_coords(image.size[0], athor.size[0], self.x)
     y1 = get_coords(image.size[1], athor.size[1], self.y)
     box = (
         x1,
         y1,
         x1 + x2,
         y1 + y2,
     )
     # Note that if you paste an "RGBA" image, the alpha band is ignored.
     # You can work around this by using the same image as both source image and mask.
     image = image.copy()
     if athor.mode == 'RGBA':
         if image.mode == 'RGBA':
             channels = image.split()
             alpha = channels[3]
             image = Image.merge('RGB', channels[0:3])
             athor_channels = athor.split()
             athor_alpha = athor_channels[3]
             athor = Image.merge('RGB', athor_channels[0:3])
             image.paste(athor, box, mask=athor_alpha)
             # merge alpha
             athor_image_alpha = Image.new('L', image.size, color=0)
             athor_image_alpha.paste(athor_alpha, box)
             new_alpha = ImageChops.add(alpha, athor_image_alpha)
             image = Image.merge('RGBA', image.split() + (new_alpha,))
         else:
             image.paste(athor, box, mask=athor)
     else:
         image.paste(athor, box)
     return image
 def execute(self, image, query):
     from imagequery import ImageQuery # late import to avoid circular import
     image = image.copy()
     font = get_font_object(self.font, self.size)
     size, offset = ImageQuery.img_textbox(self.text, self.font, self.size)
     x = get_coords(image.size[0], size[0], self.x) + offset[0]
     y = get_coords(image.size[1], size[1], self.y) + offset[1]
     draw = ImageDraw.Draw(image)
     text = smart_unicode(self.text)
     draw.text((x, y), text, font=font, fill=self.fill)
     return image
Example #4
0
    def execute(self, image, query):
        from imagequery import ImageQuery  # late import to avoid circular import

        image = image.copy()
        font = get_font_object(self.font, self.size)
        size, offset = ImageQuery.img_textbox(self.text, self.font, self.size)
        x = get_coords(image.size[0], size[0], self.x) + offset[0]
        y = get_coords(image.size[1], size[1], self.y) + offset[1]
        draw = ImageDraw.Draw(image)
        text = smart_text(self.text)
        draw.text((x, y), text, font=font, fill=self.fill)
        return image
Example #5
0
 def execute(self, image, query):
     background = Image.new('RGBA', image.size, color=(0, 0, 0, 0))
     athor = get_image_object(self.image, self.storage)
     x2, y2 = image.size
     x1 = get_coords(image.size[0], athor.size[0], self.x)
     y1 = get_coords(image.size[1], athor.size[1], self.y)
     box = (
         x1,
         y1,
         x1 + x2,
         y1 + y2,
     )
     background.paste(athor, box, mask=athor)
     background.paste(image, None, mask=image)
     return background
 def execute(self, image, query):
     background = Image.new('RGBA', image.size, color=(0,0,0,0))
     athor = get_image_object(self.image, self.storage)
     x2,y2 = image.size
     x1 = get_coords(image.size[0], athor.size[0], self.x)
     y1 = get_coords(image.size[1], athor.size[1], self.y)
     box = (
         x1,
         y1,
         x1 + x2,
         y1 + y2,
     )
     background.paste(athor, box, mask=athor)
     background.paste(image, None, mask=image)
     return background