Skip to content

Commit 2a92f2c

Browse files
Realised it isn't always top left bc of text anchor, so that was
misleading
1 parent b57fb2e commit 2a92f2c

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

ballsdex/core/image_generator/image_gen.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@
2121
"is_attribute": True,
2222
"is_image": True,
2323
"source": ["special_card", "countryball.cached_regime.background"],
24-
"top_left": (0, 0),
24+
"anchor": (0, 0),
2525
"size": (WIDTH, HEIGHT),
2626
},
2727
"card_art": {
2828
"is_attribute": True,
2929
"is_image": True,
3030
"source": "countryball.collection_card",
31-
"top_left": (34, 261),
31+
"anchor": (34, 261),
3232
"size": (1359, 731),
3333
},
3434
"title": {
3535
"is_attribute": True,
3636
"is_image": False,
3737
"source": ["countryball.short_name", "countryball.country"],
38-
"top_left": (50, 20),
38+
"anchor": (50, 20),
3939
"text_font": "ArsenicaTrial-Extrabold.ttf",
4040
"text_font_size": 170,
4141
"text_stroke_width": 2,
@@ -45,7 +45,7 @@
4545
"is_attribute": True,
4646
"is_image": False,
4747
"source": "countryball.capacity_name",
48-
"top_left": (100, 1050),
48+
"anchor": (100, 1050),
4949
"text_line_height": 100,
5050
"text_font": "Bobby Jones Soft.otf",
5151
"text_wrap": 26,
@@ -58,7 +58,7 @@
5858
"is_attribute": True,
5959
"is_image": False,
6060
"source": "countryball.capacity_description",
61-
"top_left": (60, "capacity_name"),
61+
"anchor": (60, "capacity_name"),
6262
"text_line_height": 100,
6363
"text_font": "OpenSans-Semibold.ttf",
6464
"text_wrap": 32,
@@ -71,7 +71,7 @@
7171
"is_attribute": True,
7272
"is_image": False,
7373
"source": "health",
74-
"top_left": (320, 1670),
74+
"anchor": (320, 1670),
7575
"text_line_height": 100,
7676
"text_font": "Bobby Jones Soft.otf",
7777
"text_wrap": 32,
@@ -84,7 +84,7 @@
8484
"is_attribute": True,
8585
"is_image": False,
8686
"source": "attack",
87-
"top_left": (1120, 1670),
87+
"anchor": (1120, 1670),
8888
"text_line_height": 100,
8989
"text_font": "Bobby Jones Soft.otf",
9090
"text_wrap": 32,
@@ -98,7 +98,7 @@
9898
"is_attribute": False,
9999
"is_image": False,
100100
"source": "Created by El Lagronn",
101-
"top_left": (30, 1870),
101+
"anchor": (30, 1870),
102102
"text_font": "arial.ttf",
103103
"text_line_height": 43,
104104
"text_fill": (255, 255, 255, 255),
@@ -109,7 +109,7 @@
109109
"is_attribute": True,
110110
"is_image": False,
111111
"source": "countryball.credits",
112-
"top_left": (30, "lagg_credits"),
112+
"anchor": (30, "lagg_credits"),
113113
"text_font": "arial.ttf",
114114
"text_fill": (255, 255, 255, 255),
115115
"text_font_size": 40,
@@ -120,7 +120,7 @@
120120
"is_attribute": True,
121121
"is_image": False,
122122
"source": "specialcard.credits",
123-
"top_left": (1398, 1870),
123+
"anchor": (1398, 1870),
124124
"text_font": "arial.ttf",
125125
"text_fill": (255, 255, 255, 255),
126126
"text_font_size": 40,
@@ -155,7 +155,7 @@ class TemplateLayer(NamedTuple):
155155
# Otherwise its a string
156156
is_image: bool
157157
source: list[str] | str
158-
top_left: tuple[int | str, int | str]
158+
anchor: tuple[int | str, int | str]
159159
size: tuple[int, int] = (0, 0)
160160

161161
# Template string with $data to-be-replaced by the data
@@ -191,17 +191,18 @@ def draw_layer(
191191
prior_layer_info: dict[str, LayerInfo],
192192
name: str,
193193
):
194-
if isinstance(layer.top_left[0], int):
195-
startx = layer.top_left[0]
194+
if isinstance(layer.anchor[0], int):
195+
startx = layer.anchor[0]
196196
else:
197-
startx = prior_layer_info[layer.top_left[0]].finished_coords[0]
197+
startx = prior_layer_info[layer.anchor[0]].finished_coords[0]
198198

199-
if isinstance(layer.top_left[1], int):
200-
starty = layer.top_left[1]
199+
if isinstance(layer.anchor[1], int):
200+
starty = layer.anchor[1]
201201
else:
202-
starty = prior_layer_info[layer.top_left[1]].finished_coords[1]
202+
starty = prior_layer_info[layer.anchor[1]].finished_coords[1]
203203

204204
start_coords = (startx, starty)
205+
end_coords = (startx + layer.size[0], starty + layer.size[1])
205206
draw = ImageDraw.Draw(image)
206207

207208
data: str | None
@@ -238,12 +239,7 @@ def draw_layer(
238239
layer_image = ImageOps.fit(layer_image, layer.size)
239240
image.paste(layer_image, start_coords, mask=layer_image)
240241

241-
prior_layer_info[name] = LayerInfo(
242-
finished_coords=(
243-
start_coords[0] + layer.size[0],
244-
start_coords[1] + layer.size[1],
245-
)
246-
)
242+
prior_layer_info[name] = LayerInfo(finished_coords=end_coords)
247243
else:
248244
final_str: str = (
249245
layer.text_template.replace("$data", data) if layer.text_template else data

0 commit comments

Comments
 (0)