【发布时间】:2022-01-08 10:17:12
【问题描述】:
我有一组图像(frame0.jpg 到 frame15.jpg),我想在黄色背景的网格中显示:
from PIL import Image
# yellow background
img = Image.new("RGBA", (1920, 1080), (255, 216, 0, 255))
img_w, img_h = img.size
offset = 20
rows = 4
columns = 4
frame_w = img_w // rows - offset
frame_h = img_h // columns - offset
total_frames = rows * columns
x, y = 15, 15
for i in range(0, total_frames):
frame_on_the_row = Image.open("frame" + str(i) + ".jpg", "r")
img.paste(frame_on_the_row, (x, y))
x += frame_w + 15 # its offset I choose empirically
if x > img_w - frame_w:
x = 15
y += frame_h + 15
img.save("out.png")
输出示例:
如您所见,底部和右侧的黄色边框比其他黄线略宽。我怎样才能使它们都一样宽?
【问题讨论】: