-
Notifications
You must be signed in to change notification settings - Fork 0
/
gif.py
48 lines (41 loc) · 1.33 KB
/
gif.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
import logging
import sys
from PIL import Image
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
NUM_IMAGES = 36
INDEX_LENGTH = 2
def make_gif(uuid, image_path):
shoe_folder_path = os.path.join(image_path, uuid)
gif_folder_path = shoe_folder_path
img_folder_path = shoe_folder_path
if os.path.exists(os.path.join(gif_folder_path, "spinning.gif")):
return False
logging.info(f"Creating gif for {uuid}.")
img_files = [f for f in os.listdir(img_folder_path) if f.endswith(".jpg")]
num_images = len(img_files)
frames = [
Image.open(os.path.join(img_folder_path, f"{str(i).zfill(INDEX_LENGTH)}.jpg"))
for i in range(1, num_images + 1)
]
os.makedirs(gif_folder_path, exist_ok=True)
gif_path = os.path.join(gif_folder_path, "spinning.gif")
frames[0].save(
gif_path,
format="GIF",
append_images=frames[1:],
save_all=True,
duration=100,
loop=0,
)
logging.info(f"Created gif for {uuid}.")
return True
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python script.py <uuid> <image_path>")
sys.exit(1)
uuid = sys.argv[1]
image_path = sys.argv[2]
# Example of calling make_gif using system arguments
make_gif(uuid, image_path)
print("GIF creation complete.")