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): # TODO: Use putalpha(band)? image = image.convert('RGBA') alphamap = get_image_object(self.alphamap).convert('RGBA') data = image.split()[self.channel_map['red']:self.channel_map['alpha']] alpha = alphamap.split()[self.channel_map['alpha']] alpha = alpha.resize(image.size, Image.ANTIALIAS) return Image.merge('RGBA', data + (alpha, ))
def execute(self, image, query): # TODO: Use putalpha(band)? image = image.convert('RGBA') alphamap = get_image_object(self.alphamap).convert('RGBA') data = image.split()[self.channel_map['red']:self.channel_map['alpha']] alpha = alphamap.split()[self.channel_map['alpha']] alpha = alpha.resize(image.size, Image.ANTIALIAS) return Image.merge('RGBA', data + (alpha,))
def __init__(self, image, source=None, storage=default_storage, cache_storage=None): self.image = get_image_object(image, storage) self.source = smart_unicode(source) self.storage = storage if cache_storage is None: if default_cache_storage is None: cache_storage = storage else: cache_storage = default_cache_storage self.cache_storage = cache_storage self.query = QueryItem()
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
def execute(self, image, query): athor = get_image_object(self.image, self.storage) mask = get_image_object(self.mask, self.storage) return Image.composite(image, athor, mask)
def execute(self, image, query): athor = get_image_object(self.image, self.storage) return Image.blend(image, athor, self.alpha)