Created
June 1, 2022 21:15
-
-
Save gingershaped/b2ad482532028a25e05c38c4f9f82362 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image, ImageDraw, ImageColor | |
from os.path import splitext | |
OPACITY = 150 | |
COLORS = [ | |
(*ImageColor.getrgb("red"), OPACITY), | |
(*ImageColor.getrgb("orange"), OPACITY), | |
(*ImageColor.getrgb("yellow"), OPACITY), | |
(*ImageColor.getrgb("green"), OPACITY), | |
(*ImageColor.getrgb("blue"), OPACITY), | |
(*ImageColor.getrgb("purple"), OPACITY), | |
] | |
file = input("Filename: ") | |
out = splitext(file)[0] + "-pride.png" | |
with Image.open(file).convert("RGB") as im: | |
e = int(im.height / (len(COLORS) - 1)) | |
draw = ImageDraw.Draw(im, "RGBA") | |
for c, y in enumerate(range(0, im.height, e)): | |
draw.rectangle((0, y, im.width, y+e-1), fill = COLORS[c]) | |
im.save(out) | |
print("File saved to", out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment