canvas.py

413 B · python · 16 lines

1import math23from PIL import Image4from mrlypy.core.colors import ink56H3 = math.sqrt(3) / 27INK = ink("black")8PAPER = ink("white")910def flatten(image, background=PAPER):11    canvas = Image.new("RGB", image.size, background.to_rgb())12    canvas.paste(image, (0, 0), image)13    return canvas1415def quantize(image, colors):16    return image.quantize(colors=colors, method=Image.MEDIANCUT, dither=Image.Dither.NONE)