Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,13 +13,22 @@ def generate_map(image_files, canvas_size=(3000, 3000)):
|
|
13 |
if not image_files:
|
14 |
return canvas
|
15 |
|
16 |
-
|
|
|
|
|
|
|
17 |
img_path = os.path.join(map_dir, img_file)
|
18 |
with Image.open(img_path) as img:
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
return canvas
|
25 |
|
|
|
13 |
if not image_files:
|
14 |
return canvas
|
15 |
|
16 |
+
grid_size = int(len(image_files) ** 0.5) + 1 # Calculate grid size
|
17 |
+
img_size = canvas_size[0] // grid_size # Size for each image cell
|
18 |
+
|
19 |
+
for idx, img_file in enumerate(image_files):
|
20 |
img_path = os.path.join(map_dir, img_file)
|
21 |
with Image.open(img_path) as img:
|
22 |
+
# Maintain aspect ratio
|
23 |
+
img.thumbnail((img_size, img_size), Image.ANTIALIAS)
|
24 |
+
|
25 |
+
# Calculate grid position
|
26 |
+
row, col = divmod(idx, grid_size)
|
27 |
+
x = col * img_size
|
28 |
+
y = row * img_size
|
29 |
+
|
30 |
+
# Paste the image on the canvas
|
31 |
+
canvas.paste(img, (x, y), mask=img if img.mode == "RGBA" else None)
|
32 |
|
33 |
return canvas
|
34 |
|