34 lines
646 B
Python
34 lines
646 B
Python
from PIL import Image
|
|
import os
|
|
import re
|
|
|
|
frame_folder = "./output"
|
|
output_gif = "output.gif"
|
|
|
|
# same duration for every frame (in milliseconds)
|
|
frame_duration = 250
|
|
|
|
def frame_number(filename):
|
|
return int(re.search(r"frame_(\d+)\.png", filename).group(1))
|
|
|
|
files = [
|
|
f for f in os.listdir(frame_folder)
|
|
if f.startswith("frame_") and f.endswith(".png")
|
|
]
|
|
|
|
files.sort(key=frame_number)
|
|
|
|
frames = [
|
|
Image.open(os.path.join(frame_folder, f)).convert("RGBA")
|
|
for f in files
|
|
]
|
|
|
|
frames[0].save(
|
|
output_gif,
|
|
save_all=True,
|
|
append_images=frames[1:],
|
|
duration=frame_duration,
|
|
loop=0
|
|
)
|
|
|
|
print(f"Saved {output_gif}") |