#!/bin/env python3 from collections import defaultdict from PIL import Image from colors import Colors TILE_HEIGHT = TILE_WIDTH = 60 OUTPUT_SIZE = (40, 50) COLORS_FILENAME = "data/bead_colors_perler_standard.json" # Generate a palette from available colors COLORS = Colors(COLORS_FILENAME) PALETTE_IMAGE = COLORS.get_palette() def adjust_channels(image, red=1.1, green=1.1, blue=1.1): return image.convert(mode="RGB").convert(mode="RGB", matrix=(red, 0, 0, 0, 0, green, 0, 0, 0, 0, blue, 0)) def dither(image): return image.quantize(palette=PALETTE_IMAGE, method=0) def resize(image, output_size=OUTPUT_SIZE): return image.resize(output_size, Image.LANCZOS)