Python电视剧电影台词拼接图
效果图(成果大大好帅)
代码(需要自己调参)
from PIL import Image
print('截图')
for i in range(1,9):
img = Image.open('./原图/%d.png'%i)
w, h = img.size
print(w, h)
if i != 1:
box = (0, 930, 1920, 1050)
img = img.crop(box)
# 保存截取的图片
img.save('./截图/%d.png'%i)
print('计算')
x, y = 0, 0
for i in range(1,9):
img = Image.open('./截图/%d.png'%i)
w, h = img.size
x = w
y += h
print(x, y)
print('拼接')
height = 0
out = Image.new("RGB", (x, y-30))
for i in range(1,9):
img = Image.open('./截图/%d.png'%i)
out.paste(img, (0, height))
if i == 1:
height += 1050
else:
height += h
out.save("out.png")
2.0版本
调整下基本参数就行,剩下计算逻辑都设定好了
from PIL import Image
# 文件夹两个,<原图>存储原图,<截图>存储过程
start = 3 # 起始文件名编号
last = 14 # 结束文件名编号
top = 925 # 上线
bottom = 1005 # 下线
print('截图')
for i in range(start,last+1):
img = Image.open('./原图/%d.png'%i)
w1, h1 = img.size
print(w1, h1)
if i != start:
box = (0, top, w1, bottom)
img = img.crop(box)
# 保存截取的图片
img.save('./截图/%d.png'%i)
print('计算')
x, y = 0, 0
for i in range(start,last+1):
img = Image.open('./截图/%d.png'%i)
w2, h2 = img.size
x = w2
y += h2
print(x, y)
print('拼接')
height = 0
out = Image.new("RGB", (x, y-(h1-bottom)))
for i in range(start,last+1):
img = Image.open('./截图/%d.png'%i)
out.paste(img, (0, height))
if i == start:
height += bottom
else:
height += h2
out.save("out.png")