-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
73 lines (55 loc) · 2.12 KB
/
main.py
File metadata and controls
73 lines (55 loc) · 2.12 KB
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
from PIL import Image
from datetime import datetime
from library.Counting import GetCountingPhoto
class GetIce:
def __init__(self,img_path):
self.spring_festival = (2026, 3, 17)
self.img_path = img_path
self.top = 10 #顶部预留像素
self.bottom = 15 #底部预留像素
def get_percent(self):
spring_festival = datetime(self.spring_festival[0], self.spring_festival[1], self.spring_festival[2])
now = datetime.now()
left = spring_festival - now
percent = left.total_seconds() / (60 * 60 * 24 * 365)
if percent < 0:
percent = 0
if percent > 1:
percent = 1
percent = float(format(percent, '.5f'))
return percent
def get_img(self):
percent = self.get_percent()
ice = Image.open(self.img_path+"/ice.png")
bg_ice = Image.open(self.img_path+"/bg_ice.png")
ldh = Image.open(self.img_path+"/ldh.png")
img = Image.new("RGBA", (ldh.width, ldh.height), (255, 255, 255,0))
if percent > 0:
h = ice.height - int((ice.height - self.top - self.bottom) * percent + self.bottom + self.bottom)
t = bg_ice.crop((0, h, bg_ice.width, bg_ice.height))
img.paste(t, (0,h), t)
img.paste(ldh, (0, 0), ldh)
t = ice.crop((0, h, ice.width, ice.height))
img.paste(t, (0, h), t)
else:
img.paste(ldh, (0, 0), ldh)
return img
def main():
weight = 1000
height = 600
counting = GetCountingPhoto(r"fonts")
counting.spring_festival = (2026, 2, 17)
light_counting, dark_counting = counting.get_photo()
t = GetIce("./img")
t.spring_festival = (2026, 2, 17)
ldh = t.get_img()
dark = Image.new("RGBA", (weight, height), (0, 0, 0, 0))
light = Image.new("RGBA", (weight, height), (255, 255, 255, 0))
dark.paste(ldh, (0, 50), ldh)
light.paste(ldh, (0, 50), ldh)
dark.paste(dark_counting,(500,400), dark_counting)
light.paste(light_counting, (500, 400), light_counting)
dark.save("dark.png")
light.save("light.png")
if __name__ == '__main__':
main()