Skip to content

Instantly share code, notes, and snippets.

@gingershaped
Created June 1, 2022 21:15
Show Gist options
  • Save gingershaped/b2ad482532028a25e05c38c4f9f82362 to your computer and use it in GitHub Desktop.
Save gingershaped/b2ad482532028a25e05c38c4f9f82362 to your computer and use it in GitHub Desktop.
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