-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayer_marquee.py
More file actions
executable file
·143 lines (111 loc) · 4.44 KB
/
Copy pathlayer_marquee.py
File metadata and controls
executable file
·143 lines (111 loc) · 4.44 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python3
"""
Script to layer marquee images on top of the Neo Geo base image.
Fills all four marquee slots with random, non-repeating marquees.
The marquee images (27x31) are placed at positions:
Slot 1: (79, 141)
Slot 2: (145, 141)
Slot 3: (214, 141)
Slot 4: (277, 141)
"""
import os
import random
import sys
from PIL import Image
def get_available_marquees(marquees_dir, exclude_blank=True):
"""
Get list of available marquee images from the marquees directory.
Args:
marquees_dir: Path to the marquees directory
exclude_blank: If True, excludes _blank.png from the list
Returns:
List of marquee file paths
"""
marquees = []
if not os.path.exists(marquees_dir):
print(f"Error: Marquees directory not found at {marquees_dir}")
return marquees
for filename in os.listdir(marquees_dir):
if filename.endswith(".png"):
if exclude_blank and filename == "_blank.png":
continue
marquees.append(os.path.join(marquees_dir, filename))
return marquees
def layer_marquees(base_image, marquee_paths, output_path):
"""
Layer multiple marquee images on top of a base image at predefined positions.
Args:
base_image: PIL Image object (already has backlight effect applied)
marquee_paths: List of up to 4 marquee image paths to overlay
output_path: Path where the output image will be saved
"""
# Define the four slot positions
positions = [
(79, 141), # Slot 1
(145, 141), # Slot 2
(214, 141), # Slot 3
(277, 141), # Slot 4
]
print(f"Base image dimensions: {base_image.size}")
# Create a copy of the base image to work with
result = base_image.copy()
# Layer each marquee at its corresponding position
for i, marquee_path in enumerate(marquee_paths[:4]): # Limit to 4 slots
if i >= len(positions):
break
# Open the marquee image
marquee = Image.open(marquee_path).convert("RGBA")
position = positions[i]
marquee_name = os.path.basename(marquee_path)
print(
f"Slot {i + 1}: Placing '{marquee_name}' at position {position} (size: {marquee.size})"
)
# Paste the marquee onto the result image at the specified position
# Using the marquee's alpha channel as the mask for transparency
result.paste(marquee, position, marquee)
# Save the result
result.save(output_path)
print(f"\nOutput saved to: {output_path}")
def main():
# Define paths
base_dir = os.path.dirname(os.path.abspath(__file__))
base_image = os.path.join(base_dir, "neogeo.png")
marquees_dir = os.path.join(base_dir, "marquees")
output_image = os.path.join(base_dir, "neogeo.png")
# Check if base image exists
if not os.path.exists(base_image):
print(f"Error: Base image not found at {base_image}")
sys.exit(1)
# Get available marquees (excluding _blank.png)
available_marquees = get_available_marquees(marquees_dir, exclude_blank=True)
if not available_marquees:
print("Error: No marquee images found (excluding _blank.png)")
sys.exit(1)
print(f"Found {len(available_marquees)} available marquee(s):")
for marquee in available_marquees:
print(f" - {os.path.basename(marquee)}")
print()
# If we have fewer than 4 marquees, we need to use them multiple times
# but we'll shuffle to randomize which ones appear in which slots
if len(available_marquees) < 4:
# Duplicate the list until we have at least 4 items
extended_marquees = available_marquees.copy()
while len(extended_marquees) < 4:
extended_marquees.extend(available_marquees)
# Shuffle and take 4
random.shuffle(extended_marquees)
selected_marquees = extended_marquees[:4]
else:
# We have 4 or more marquees, randomly select 4 without replacement
selected_marquees = random.sample(available_marquees, 4)
print("Selected marquees for each slot:")
for i, marquee in enumerate(selected_marquees):
print(f" Slot {i + 1}: {os.path.basename(marquee)}")
print()
# Open the base image
base = Image.open(base_image).convert("RGBA")
# Layer the marquee cards on top
layer_marquees(base, selected_marquees, output_image)
print("Success! All four marquee slots filled with random marquees.")
if __name__ == "__main__":
main()