-
Notifications
You must be signed in to change notification settings - Fork 8
/
kuan.py
146 lines (122 loc) · 3.83 KB
/
kuan.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Date : 2021-01-09 15:26:05
# @Author : Lewis Tian ([email protected])
# @Link : github.com/taseikyo
# @Version : python3.8
import os
from datetime import datetime
from PIL import Image, ImageDraw, ImageFont
def fefive_phone(year=2020):
"""
一事无成手机壁纸
"""
# 壁纸宽高,底色
w, h = 1080, 2340
color = (0, 0, 0)
text_color = (255, 255, 255)
font_family = "calibri"
year_size = 90
text_size = 65
out_img = Image.new(mode="RGB", size=(w, h), color=color)
draw = ImageDraw.Draw(out_img)
year_font = ImageFont.truetype(font_family, year_size)
text_font = ImageFont.truetype(font_family, text_size)
year_text = f"{year} -- {datetime.now().year}"
five_text = f"{datetime.now().year-year} years, you still have nothing"
year_w, year_h = ImageDraw.Draw(Image.new(mode="RGB", size=(1, 1))).textsize(
year_text, font=year_font
)
text_w, _ = ImageDraw.Draw(Image.new(mode="RGB", size=(1, 1))).textsize(
five_text, font=text_font
)
# 年份的 y 位置
year_y = 650
line_space = 30
draw.text(
((w - year_w) // 2, year_y),
year_text,
font=year_font,
fill=text_color,
)
draw.text(
((w - text_w) // 2, year_y + year_h + line_space),
five_text,
font=text_font,
fill=text_color,
)
if not os.path.exists("img"):
os.mkdir("img")
out_img.save(f"img/{year}.png")
print(f"generated images path: img/{year}.png")
def fefive_pc(year=2020, align="center"):
"""
电脑壁纸
@align: ["center", "rb", "rt", "lb", lt]
五个可选参数,分别为 居中 右下 右上 左下 左上
right-bottom -> rb
"""
# 壁纸宽高,底色
w, h = 1920, 1080
color = (0, 0, 0)
text_color = (255, 255, 255)
font_family = "calibri"
year_size = 90
text_size = 65
out_img = Image.new(mode="RGB", size=(w, h), color=color)
draw = ImageDraw.Draw(out_img)
year_font = ImageFont.truetype(font_family, year_size)
text_font = ImageFont.truetype(font_family, text_size)
year_text = f"{year} -- {datetime.now().year}"
five_text = f"{datetime.now().year-year} years, you still have nothing"
year_w, year_h = ImageDraw.Draw(Image.new(mode="RGB", size=(1, 1))).textsize(
year_text, font=year_font
)
text_w, text_h = ImageDraw.Draw(Image.new(mode="RGB", size=(1, 1))).textsize(
five_text, font=text_font
)
line_space = 30
right_padding = 100
left_padding = 100
bottom_padding = 150
top_padding = 150
# 年份的 y 位置
if align == "rb":
year_y = h - line_space - year_h - text_h - bottom_padding
year_x = w - year_w - right_padding
text_x = w - text_w - right_padding
elif align == "rt":
year_y = top_padding
year_x = w - year_w - right_padding
text_x = w - text_w - right_padding
elif align == "lb":
year_y = h - line_space - year_h - text_h - bottom_padding
year_x = left_padding
text_x = left_padding
elif align == "lt":
year_y = top_padding
year_x = left_padding
text_x = left_padding
else:
year_y = (h - line_space - year_h) // 2
year_x = (w - year_w) // 2
text_x = (w - text_w) // 2
draw.text(
(year_x, year_y),
year_text,
font=year_font,
fill=text_color,
)
draw.text(
(text_x, year_y + year_h + line_space),
five_text,
font=text_font,
fill=text_color,
)
if not os.path.exists("img"):
os.mkdir("img")
out_img.save(f"img/{year}_pc.png")
print(f"generated images path: img/{year}_pc.png")
if __name__ == "__main__":
[fefive_phone(i) for i in range(1980, 2021)]
fefive_pc(1949, "rb")