inky = Inky() saturation = 0.5 # Saturation of palette thresholds = [64, 64, 64] # Threshold for snapping colours, I guess? if len(sys.argv) == 1: print(""" Usage: {file} image-file """.format(file=sys.argv[0])) sys.exit(1) if len(sys.argv) > 2: saturation = float(sys.argv[2]) palette = hitherdither.palette.Palette( inky._palette_blend(saturation, dtype='uint24')) image = Image.open(sys.argv[1]).convert("RGB") # VERY slow (1m 40s on a Pi 4) - see https://github.com/hbldh/hitherdither for a list of methods # image_dithered = hitherdither.diffusion.error_diffusion_dithering(image, palette, method="stucki", order=2) # Usably quick, your vanilla dithering # image_dithered = hitherdither.ordered.bayer.bayer_dithering(image, palette, thresholds, order=8) # Usuably quick, half-tone comic-book feel, use order=4 for small dots and order=8 dot bigguns image_dithered = hitherdither.ordered.cluster.cluster_dot_dithering(image, palette, thresholds, order=8) # VERY slow
names = ['black', 'white', 'green', 'blue', 'red', 'yellow', 'orange'] if args.file is None: print("You must specify an output palette file.") sys.exit(1) def raw_palette(): palette = bytearray(768) palette[0:8 * 3] = inky._palette_blend(args.saturation, dtype='uint8') return palette if args.type == 'css': palette = inky._palette_blend(args.saturation, dtype='uint24') with open(args.file, 'w+') as f: for i in range(7): name = names[i] colour = palette[i] f.write(""".{name}_fg {{font-color:#{colour:06x}}} .{name}_bg {{background-color:#{colour:06x}}} """.format(name=name, colour=colour)) if args.type == 'gpl': palette = inky._palette_blend(args.saturation, dtype='uint24') with open(args.file, 'w+') as f: f.write("GIMP Palette\n") f.write("Name: InkyImpressions\n") f.write("Columns: 7\n") for i in range(7):