-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.py
More file actions
35 lines (28 loc) · 790 Bytes
/
convert.py
File metadata and controls
35 lines (28 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from PIL import Image
from typing import List
from PIL.PngImagePlugin import PngImageFile
def convert_to_gif(input_file: List[str], output_path: str, *args, **kw):
if kw.get("speed"):
speed = kw.get("speed")
else:
speed = 2
images: List[PngImageFile] = []
for file in input_file:
images.append(Image.open(file))
if len(input_file) > 1:
images[0].save(
fp = output_path,
format="gif",
append_images = images[1:],
save_all=True,
duration = speed * 1000,
loop = 0
)
else:
images[0].save(
fp = output_path,
format="gif",
save_all=True,
duration = speed * 1000,
loop = 0
)