def posterize(image, bits, amount=100): """Apply a filter - amount: 0-1""" image = imtools.convert_safe_mode(image) posterized = imtools.remove_alpha(image) posterized = ImageOps.posterize(posterized, bits) if imtools.has_alpha(image): imtools.put_alpha(posterized, imtools.get_alpha(image)) if amount < 100: return imtools.blend(image, posterized, amount / 100.0) return posterized
def equalize(image, amount=100): image = imtools.convert_safe_mode(image) if imtools.has_alpha(image): equalized = imtools.remove_alpha(image) else: equalized = image equalized = ImageOps.equalize(equalized) if imtools.has_alpha(image): imtools.put_alpha(equalized, imtools.get_alpha(image)) if amount < 100: equalized = imtools.blend(image, equalized, amount / 100.0) return equalized
def autocontrast(image, amount=100.0, cutoff=0): """Apply a filter - amount: 0-1 - repeat: how many times it should be repeated""" image = imtools.convert_safe_mode(image) if imtools.has_transparency(image): im = imtools.remove_alpha(image) else: im = image contrasted = ImageOps.autocontrast(im, cutoff) if imtools.has_transparency(image): imtools.put_alpha(contrasted, imtools.get_alpha(image)) if amount < 100: return imtools.blend(image, contrasted, amount / 100.0) return contrasted