-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaving.py
85 lines (77 loc) · 2.12 KB
/
saving.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""contains functions for saving images and gifs."""
import os
import imageio.v2 as imageio
def gif_maker(type,filename, cur_file_loc, seed, pixel_number, frames, filecount):
"""Creates a gif from a list of images."""
images = []
for i in range(len(filename)):
if filename[i] != "":
images.append(imageio.imread(filename[i]))
gif_name = (
cur_file_loc
+ "\\gifs\\"
+ type
+ "seed_"
+ str(seed)
+ "pixel_"
+ str(pixel_number)
+ "frames_"
+ str(frames)
+ str(filecount)
+ ".gif"
)
server_gif_name = (
type
+ "seed_"
+ str(seed)
+ "pixel_"
+ str(pixel_number)
+ "frames_"
+ str(frames)
+ str(filecount)
+ ".gif"
)
while os.path.isfile(gif_name):
filecount += 1
gif_name = (
cur_file_loc
+ "\\gifs\\"
+ type
+ "seed_"
+ str(seed)
+ "pixel_"
+ str(pixel_number)
+ "frames_"
+ str(frames)
+ str(filecount)
+ ".gif"
)
imageio.mimsave(gif_name, images, "GIF", disposal=2, loop=0)
while os.path.isfile(server_gif_name):
filecount += 1
server_gif_name = (
type
+ "seed_"
+ str(seed)
+ "pixel_"
+ str(pixel_number)
+ "frames_"
+ str(frames)
+ str(filecount)
+ ".gif"
)
return server_gif_name
def image_saver(img, file_name):
"""Saves an image to the Images folder."""
filecount = 0
name = ""
server_name = ""
cur_file_loc = os.path.dirname(os.path.realpath(__file__))
while os.path.isfile(
cur_file_loc + "\\Images\\" + file_name + str(filecount) + ".png"
):
filecount += 1
name = cur_file_loc + "\\Images\\" + file_name + str(filecount) + ".png"
server_name = file_name + str(filecount) + ".png"
img.save(cur_file_loc + "\\Images\\" + file_name + str(filecount) + ".png")
return name, server_name