Files

142 lines
5.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""生成 8 张 1920x1080 讲解视频卡片画面"""
from PIL import Image, ImageDraw, ImageFont
import os
W, H = 1920, 1080
OUT = os.path.dirname(os.path.abspath(__file__))
FONT_R = "C:/Windows/Fonts/msyh.ttc"
FONT_B = "C:/Windows/Fonts/msyhbd.ttc"
def gradient_bg(top=(10, 22, 40), bottom=(26, 42, 74)):
img = Image.new("RGB", (W, H), top)
draw = ImageDraw.Draw(img)
for y in range(H):
r = int(top[0] + (bottom[0]-top[0])*y/H)
g = int(top[1] + (bottom[1]-top[1])*y/H)
b = int(top[2] + (bottom[2]-top[2])*y/H)
draw.line([(0,y),(W,y)], fill=(r,g,b))
return img
def text_w(draw, txt, font):
bbox = draw.textbbox((0,0), txt, font=font)
return bbox[2]-bbox[0], bbox[3]-bbox[1]
def make_slide(idx, tag, title, bullets, out_name, accent=(255, 200, 80)):
img = gradient_bg()
draw = ImageDraw.Draw(img)
# 装饰线
draw.rectangle([(0,0),(W,8)], fill=accent)
# 顶部标签
f_tag = ImageFont.truetype(FONT_B, 36)
draw.text((100, 80), tag, font=f_tag, fill=accent)
# 标题
f_title = ImageFont.truetype(FONT_B, 84)
# 标题可能换行
lines = title.split("\n")
y = 220
for line in lines:
w, h = text_w(draw, line, f_title)
draw.text(((W-w)//2, y), line, font=f_title, fill=(255,255,255))
y += h + 20
# 分隔线
draw.line([(W//2-200, y+30),(W//2+200, y+30)], fill=accent, width=3)
# bullet 列表
f_b = ImageFont.truetype(FONT_R, 44)
y2 = y + 90
for b in bullets:
bw, bh = text_w(draw, b, f_b)
draw.text(((W-bw)//2, y2), b, font=f_b, fill=(220,230,245))
y2 += bh + 28
# 底部
f_foot = ImageFont.truetype(FONT_R, 28)
foot = "考研英语一 · 完形精讲 · Margaret Hamilton 与登月软件"
fw, fh = text_w(draw, foot, f_foot)
draw.text(((W-fw)//2, H-70), foot, font=f_foot, fill=(140,160,190))
path = os.path.join(OUT, out_name)
img.save(path, quality=92)
print("saved", path)
slides = [
dict(
idx=1, tag="SECTION 01 / 开场",
title="完形精讲 第1篇",
bullets=["Margaret Hamilton 与登月软件",
"卫报模拟卷 · 英语一 · 完形 20 题",
"三大考点:固定搭配 · 语义辨析 · 逻辑连接"],
out_name="slide01.png",
),
dict(
idx=2, tag="SECTION 02 / 背景",
title="1969 · 登月前的几秒钟",
bullets=["Margaret Hamilton:阿波罗 11 号机载软件负责人",
"着陆前几分钟计算机报警 · 是否中止任务?",
"错误检测与恢复软件 · 救了整个任务"],
out_name="slide02.png",
),
dict(
idx=3, tag="SECTION 03 / 第一段 · 生平",
title="考点 1–5",
bullets=["1. when era 后接时间定语从句",
"2. under under the tutelage of 在…指导下",
"3. perfect perfect one's craft 精进技艺",
"4. at jump at the opportunity 抓住机会",
"5. and the first programmer…and the first woman"],
out_name="slide03.png",
),
dict(
idx=4, tag="SECTION 04 / 第二段 · 惊魂",
title="考点 6–12",
bullets=["6. landing by doing 结构",
"7. emergency 报警提示紧急情况",
"8. continued the spacecraft continued on",
"9. intended as…had intended 正如所设计",
"10. but not only…but also 不仅…而且",
"11. priority highest priority tasks 最高优先级",
"12. rescue come to the rescue 前来救场"],
out_name="slide04.png",
),
dict(
idx=5, tag="SECTION 05 / 第三段 · 荣誉",
title="考点 13–15",
bullets=["13. recalled 奥巴马授勋时回忆起这件事",
"14. fortunately 幸好他们有 Margaret Hamilton",
"15. but no choice but to 别无选择只能",
"",
"金句:no time to be beginners"],
out_name="slide05.png",
),
dict(
idx=6, tag="SECTION 06 / 第四段 · 遗产",
title="考点 16–20",
bullets=["16. legacy 讣告结尾:她的遗产",
"17. influential 最具影响力的人物之一",
"18. proved 她证明了…",
"19. without 虚拟语气:没有软件就没有登月",
"20. carefully 精心编写 · 反义辨析 carelessly"],
out_name="slide06.png",
),
dict(
idx=7, tag="SECTION 07 / 必背搭配",
title="8 个核心短语",
bullets=["under the tutelage of 在某人指导下",
"jump at the opportunity 抓住机会",
"no choice but to 别无选择只能",
"come to the rescue 前来救场",
"abort the mission / compensate for",
"not only…but also / would not have been possible without"],
out_name="slide07.png",
),
dict(
idx=8, tag="SECTION 08 / 下集预告",
title="下一篇:巨龟 Jonathan",
bullets=["194 岁的世界最长寿陆地动物",
"从 DNA 甲基化模式看长寿秘密",
"阅读 Part A · Text 1"],
out_name="slide08.png",
),
]
for s in slides:
make_slide(**s)