9
9
root = Tk ()
10
10
root .withdraw ()
11
11
folder_selected = filedialog .askdirectory ()
12
- # print(folder_selected)
12
+
13
13
# Get list of image paths
14
14
image_paths_list = [os .path .join (folder_selected , f ) for f in os .listdir (folder_selected ) if f .endswith ('.png' )]
15
15
16
- # print(image_paths_list)
17
-
18
- # image_paths_list.sort
19
-
20
- # print(image_paths_list)
21
-
22
16
23
- def concat_images (size , shape = None ):
17
+ def image_grid (size , shape = None ):
24
18
25
19
# Open images and resize them
26
20
images = map (PIL .Image .open , image_paths_list )
27
21
28
22
images = [PIL .ImageOps .fit (img , size ) for img in images ]
29
- # print('number', len(images))
30
23
image_count = len (image_paths_list )
31
24
print (image_count )
32
25
width , height = size
@@ -40,7 +33,6 @@ def concat_images(size, shape=None):
40
33
for col in range (shape_list [0 ]):
41
34
for row in range (shape_list [1 ]):
42
35
offset = (width * col , height * row )
43
- # idx = row * shape_list[1] + col ---WRONG!
44
36
idx = row + col * shape_list [1 ]
45
37
if idx == image_count :
46
38
return final_image
@@ -50,8 +42,8 @@ def concat_images(size, shape=None):
50
42
51
43
52
44
# Create and save image grid
53
- image = concat_images (size = (421 , 750 ), shape = (9 , 4 )) # width x height
45
+ image = image_grid (size = (421 , 750 ), shape = (9 , 4 )) # ( width, height), (columns, rows)
54
46
image .save ('image' + str (random .randint (0 , 100000000 )) + '.png' , 'PNG' )
55
47
56
48
57
- # image = concat_images ((800, 800), (3, 3)) # width x height
49
+ # image = image_grid ((800, 800), (3, 3)) # width x height
0 commit comments