-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
65 lines (50 loc) · 1.6 KB
/
main.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
import logging as log
from os import listdir
from random import randrange, choice
from PIL import Image, ImageDraw, ImageFont
from reddit import get_reddit_image
from twitter import post_image_to_twitter
log.basicConfig(level=log.INFO,
format='[%(levelname)s] (%(asctime)s) - %(message)s',
datefmt='%H:%M:%S')
IMAGE_PATH = 'media/lucas-mamao.jpg'
def random_rgb() -> tuple:
return (randrange(0, 256),
randrange(0, 256),
randrange(0, 256))
def write_on_image(image_path: str):
image_pil = Image.open(image_path).convert('RGB')
image_w, image_h = image_pil.size
font_size = int(image_w / 6)
font_name = choice(listdir("fonts"))
font_path = f'fonts/{font_name}'
font_pil = ImageFont.truetype(font=font_path, size=font_size)
log.info(f'Writing on image using font: {font_name}')
image_pil_edit = ImageDraw.Draw(image_pil)
image_pil_edit.text(
xy=(image_w / 2,
font_size / 1.1),
text='Lucas',
anchor='ms',
# fill=random_rgb(),
font=font_pil,
stroke_width=2,
stroke_fill='#000000'
)
image_pil_edit.text(
xy=(image_w / 2,
image_h - (font_size / 4)),
text='mamão',
anchor='ms',
# fill=random_rgb(),
font=font_pil,
stroke_width=2,
stroke_fill='#000000'
)
image_pil.save(image_path)
def main():
get_reddit_image(subreddit='hmmm', save_path=IMAGE_PATH)
write_on_image(image_path=IMAGE_PATH)
post_image_to_twitter(image_path=IMAGE_PATH)
if __name__ == '__main__':
main()