ΣΑ
作者: SALIMARIA创建于 2025年10月5日更新于 2025年10月5日
def make_bg(): img = Image.new("RGBA", (W, H), (6,8,16,255)) d = ImageDraw.Draw(img)
# night gradient
for y in range(H):
t = y / H
r = int(12 + 8 * (1 - t))
g = int(16 + 10 * (1 - t))
b = int(30 + 38 * (1 - t))
d.line([(0, y), (W, y)], fill=(r,g,b,255))
# skyline
random.seed(33)
ground_y = int(H*0.58)
for _ in range(46):
bw = random.randint(44, 150)
bh = random.randint(140, 460)
x = random.randint(-40, W-20)
y = ground_y - bh + random.randint(-50, 50)
d.rectangle([x, y, x+bw, ground_y], fill=(10,12,24,255))
# windows
for _ in range(1400):
bw = random.randint(6, 11)
bh = random.randint(6, 11)
x = random.randint(0, W-1)
y = random.randint(int(H*0.20), ground_y-10)
if random.random() < 0.22:
col = random.choice([(255,230,150,255),(230,245,255,255),(255,185,100,255)])
d.rectangle([x, y, x+bw, y+bh], fill=col)
# wall
wall_top = ground_y + 18
d.rectangle([0, wall_top, W, H], fill=(14,14,16,255))
# font
font = None
for p in ["/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"]:
if os.path.exists(p):
font = p; break
def stamp(text, x, y, size, angle, color):
fnt = ImageFont.truetype(font, size) if font else None
tmp = Image.new("RGBA", (1,1), (0,0,0,0))
td = ImageDraw.Draw(tmp)
bbox= td.textbbox((0,0), text, font=fnt)
tw, th = bbox[2]-bbox[0], bbox[3]-bbox[1]
pad = 10
tile = Image.new("RGBA", (tw+2*pad, th+2*pad), (0,0,0,0))
tdraw= ImageDraw.Draw(tile)
tdraw.text((pad, pad), text, font=fnt, fill=color)
tile = tile.rotate(angle, expand=True,
…
内容来源: kkroening/ffmpeg-python