-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.py
37 lines (23 loc) · 1.18 KB
/
utils.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
from PIL import Image, ImageFont, ImageDraw
from datetime import datetime
from pytz import timezone
import os
import config
def get_current_time():
return datetime.now(timezone('Asia/Tehran')).strftime('%H:%M')
def generate_image(text):
image = Image.open(os.getcwd() + config.photo_filename)
W, H = image.size
draw = ImageDraw.Draw(image)
font = ImageFont.truetype(font='resources/ds-digit.TTF', size=150)
wt, ht = draw.textsize(text, font=font)
border_size = config.image_border_size
border_color = config.image_border_color
draw.text(((W - wt) / 2 - border_size, (H - ht) / 1.25 - border_size), text, font=font, fill=border_color)
draw.text(((W - wt) / 2 + border_size, (H - ht) / 1.25 - border_size), text, font=font, fill=border_color)
draw.text(((W - wt) / 2 - border_size, (H - ht) / 1.25 + border_size), text, font=font, fill=border_color)
draw.text(((W - wt) / 2 + border_size, (H - ht) / 1.25 + border_size), text, font=font, fill=border_color)
draw.text(((W - wt) / 2, (H - ht) / 1.25), text, font=font, fill=config.image_text_color)
image.save(config.image_filename)
def delete_image():
os.remove(config.image_filename)