Skip to content

Commit 52bc122

Browse files
authored
Update image_grid.py
1 parent 4a0a36d commit 52bc122

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

Diff for: image_grid.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,17 @@
99
root = Tk()
1010
root.withdraw()
1111
folder_selected = filedialog.askdirectory()
12-
# print(folder_selected)
12+
1313
# Get list of image paths
1414
image_paths_list = [os.path.join(folder_selected, f) for f in os.listdir(folder_selected) if f.endswith('.png')]
1515

16-
# print(image_paths_list)
17-
18-
# image_paths_list.sort
19-
20-
# print(image_paths_list)
21-
2216

23-
def concat_images(size, shape=None):
17+
def image_grid(size, shape=None):
2418

2519
# Open images and resize them
2620
images = map(PIL.Image.open, image_paths_list)
2721

2822
images = [PIL.ImageOps.fit(img, size) for img in images]
29-
# print('number', len(images))
3023
image_count = len(image_paths_list)
3124
print(image_count)
3225
width, height = size
@@ -40,7 +33,6 @@ def concat_images(size, shape=None):
4033
for col in range(shape_list[0]):
4134
for row in range(shape_list[1]):
4235
offset = (width * col, height * row)
43-
# idx = row * shape_list[1] + col ---WRONG!
4436
idx = row + col * shape_list[1]
4537
if idx == image_count:
4638
return final_image
@@ -50,8 +42,8 @@ def concat_images(size, shape=None):
5042

5143

5244
# 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)
5446
image.save('image' + str(random.randint(0, 100000000)) + '.png', 'PNG')
5547

5648

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

Comments
 (0)