def watermark(image, mark, horizontal_offset=None, vertical_offset=None, horizontal_justification=None, vertical_justification=None, orientation=None, method=None, opacity=100): """Adds a watermark to an image.""" if image.mode == 'P': image = convert_safe_mode(image) layer = generate_layer(image.size, mark, method, horizontal_offset, vertical_offset, horizontal_justification, vertical_justification, orientation, opacity) return Image.composite(layer, image, layer)
def background(image, fill, mark, color, horizontal_offset=None, vertical_offset=None, horizontal_justification=None, vertical_justification=None, orientation=None, method=None, opacity=100): if not has_transparency(image): return image if image.mode == 'P': image = image.convert('RGBA') if fill == FILL_CHOICES[0]: opacity = (255 * opacity) / 100 return fill_background_color(image, HTMLColorToRGBA(color, opacity)) elif fill == FILL_CHOICES[1]: layer = generate_layer(image.size, mark, method, horizontal_offset, vertical_offset, horizontal_justification, vertical_justification, orientation, opacity) paste(layer, image, mask=image) return layer