from pathlib import Path from PIL import Image # One character is exactly one pixel. The handle runs from bottom left # to top right; transparent pixels surround the outlined steel head. PIXELS = [ "................", "......oo........", ".....oWWo.......", "....oWSSSo..oo..", "...oWSSSSSooHo..", "...oWSSSSDoHho..", "....oSSSDoHho...", ".....oDDoHho....", "......ooHho.....", "......oHho......", ".....oHho.......", "....oHho........", "...oHho.........", "..oHho..........", "..oho...........", "...o............", ] PALETTE = { ".": (0, 0, 0, 0), "o": (32, 39, 49, 255), "W": (239, 250, 255, 255), "S": (169, 195, 208, 255), "D": (99, 128, 147, 255), "H": (209, 153, 78, 255), "h": (133, 82, 44, 255), } def main(): assert len(PIXELS) == 16 and all(len(row) == 16 for row in PIXELS) image = Image.new("RGBA", (16, 16)) image.putdata([PALETTE[pixel] for row in PIXELS for pixel in row]) output = Path(__file__).resolve().parent image.save(output / "axe_16x16.png") image.resize((320, 320), Image.Resampling.NEAREST).save( output / "axe_preview.png" ) with Image.open(output / "axe_16x16.png") as exported: assert exported.size == (16, 16) and exported.mode == "RGBA" print(f"Exported {output / 'axe_16x16.png'} (16 x 16, transparent RGBA)") if __name__ == "__main__": main()