Exemple #1
0
def wand_trim(pil_image):
    """
    Trim black borders from an image with ImageMagick's algorithm. This method
    seems to be more effective than PIL's ImageChops from pil_trim.

    :param pil_image: PIL.Image object
    """
    wand_img = pil_to_wand(pil_image)
    wand_img.trim(color="black", fuzz=20.0, percent_background=0.2)

    return wand_to_pil(wand_img)
Exemple #2
0
def get_colors(image, dither="floyd_steinberg"):
    """
    :param image: PIL.Image object
    :param dither: dither method from wand.image.DITHER_METHODS (version => 7)
    """
    logger.info("Extracting colors")
    magick = pil_to_wand(image)

    magick.quantize(10, dither=dither)

    magick.unique_colors()

    pil_pixels = wand_to_pil(magick)

    return list(pil_pixels.getdata())