-
-
Notifications
You must be signed in to change notification settings - Fork 173
/
generate_backgrounds.py
78 lines (62 loc) · 3.04 KB
/
generate_backgrounds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'''
generate_stripey_backgrounds.py: create 16:9 background for posting to twitter
3 November 2020
Vicki Langer (@vicki_langer) (heavily influenced by @alexwlchan) https://alexwlchan.net/2020/03/stripey-flag-wallpapers/
'''
from PIL import Image, ImageDraw, ImageFont
def create_background(colors):
# image dimensions 16:9
box_width = 1600
box_height = 900
# create blank image for twitter post
box = Image.new("RGB", size=(box_width, box_height), color="#ffffff") # test color
draw = ImageDraw.Draw(box)
# define stripes
stripe_height = 90
# left_img_middle = 700 # px from top
# right_img_middle = 200 # px from top
total_stripe_height = stripe_height * len(colors)
left_hand_top = 200 - (total_stripe_height / 2)
right_hand_top = 700 - (total_stripe_height / 2)
# draw stripes
for label, color in enumerate(colors):
draw.polygon(
[
(0, left_hand_top + stripe_height * label), # top left corner
(box_width, right_hand_top + stripe_height * label), # top right corner
(box_width, right_hand_top + stripe_height * (label + 1)), # bottom right corner
(0, left_hand_top + stripe_height * (label + 1)), # bottom left corner
],
fill=color
)
# write in the twitter handle watermark thingy
chosen_font = ImageFont.truetype('assets/Nunito-SemiBold.ttf', 60)
twitter_handle = "@LGBTQotd"
draw = ImageDraw.Draw(box)
draw.text((28, 800), text=twitter_handle, fill=("#444"), font=chosen_font)
# add transparent mask thingy to lighten image to help with a11y
# TODO: add mask
border_width = 100 # 100 works well with the text
blank_area = (border_width, border_width, box_width-border_width, box_height-border_width)
draw.rectangle(blank_area, fill="#ffffff")
# give the box
return box
# TODO: add function call to get_img_for_tweet.py
# TODO: add function to get_img_for_tweet.py to check contrast w/ WCAG standards
if __name__ == '__main__':
for label, pride_colors in [
# colors from schemecolor.com/tag/gender-flags
("progress", ["#ffffff", "#f7a8b8", "#55cdfc", "#603815", "#000000", "#d20605", "#ef9c00", "#ffe500", "#119f0b", "#031a9a", "#78028c"]),
("genderfluid", ["#F996B9", "#FFFFFF", "#CA28E3", "#333333", "#5861CD"]),
("aromantic", ["#5BBD60", "#BAD897", "#ffffff", "#BABABA", "#333333"]),
("asexual", ["#000000", "#a4a4a4", "#ffffff", "#810081"]),
("pansexual", ["#ff1b8d", "#ffda00", "#1bb3ff"]),
("trans", ["#55cdfc", "#f7a8b8", "#ffffff", "#f7a8b8", "#55cdfc"]),
("intersex", ["#ffda00", "#7a00ac"]),
("non-binary", ["#fff430", "#ffffff", "#9c59d1", "#000000"]),
("bear", ["#633800", "#d76300", "#ffde58", "#ffe7b5", "#555555", "#000000"]),
("genderqueer", ["#b77fdd", "#ffffff", "#48821e"]),
("polysexual", ["#f714ba", "#01d66a", "#1594f6"]),
]:
box = create_background(colors=pride_colors)
box.save(f"img_bg/bg_{label}.jpg")