3This is a script for creating colour-tinted versions of greyscale images.
5It works by creating an RGBA image which has the specified colour
6on every pixel, then controlling the intensity with the alpha value.
8I don't use it especially often, but I thought it was a neat trick and
9I wanted to save it for future use.
17if __name__ == "__main__":
20 hex_colour = sys.argv[2]
22 sys.exit(f"Usage: {__file__} <PATH> <HEX_COLOUR>")
24 red = int(hex_colour[1:3], 16)
25 green = int(hex_colour[3:5], 16)
26 blue = int(hex_colour[5:7], 16)
30 pixels = list(im.getdata())
31 tinted_im = Image.new("RGBA", im.size)
34 tinted_im.putdata([(red, green, blue, 255 - p) for p in pixels])
36 tinted_im.putdata([(red, green, blue, 255 - p[0]) for p in pixels])
38 name, _ = path.rsplit(".", 1)
39 out_path = f"{name}.{hex_colour.strip('#')}.png"
41 tinted_im.save(out_path)