awacke1 commited on
Commit
52c9995
·
verified ·
1 Parent(s): aa7ce45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
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
- for i, img_file in enumerate(image_files):
 
 
 
17
  img_path = os.path.join(map_dir, img_file)
18
  with Image.open(img_path) as img:
19
- img = img.resize((500, 500)) # Resize for demonstration
20
- x = (i % 5) * 600 # Example placement logic
21
- y = (i // 5) * 600
22
- canvas.paste(img, (x, y))
 
 
 
 
 
 
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