Commit ·
46f20a7
1
Parent(s): a2e7972
fix: Text Story UI positioning, Fact Image heading background alignment
Browse files
modules/fact_image/services/text_overlay.py
CHANGED
|
@@ -221,19 +221,32 @@ class TextOverlay:
|
|
| 221 |
# Draw heading with background (UPPERCASE)
|
| 222 |
if heading:
|
| 223 |
heading_upper = heading.upper() # Convert to UPPERCASE
|
|
|
|
| 224 |
heading_bbox = draw.textbbox((0, 0), heading_upper, font=heading_font)
|
|
|
|
|
|
|
| 225 |
heading_width = heading_bbox[2] - heading_bbox[0]
|
| 226 |
heading_height = heading_bbox[3] - heading_bbox[1]
|
| 227 |
heading_x = (self.TARGET_WIDTH - heading_width) // 2
|
| 228 |
|
| 229 |
-
# Draw background
|
| 230 |
-
|
| 231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
|
|
|
|
|
|
|
| 233 |
bg_x1 = heading_x - heading_bg_padding
|
| 234 |
-
bg_y1 =
|
| 235 |
bg_x2 = heading_x + heading_width + heading_bg_padding
|
| 236 |
-
bg_y2 =
|
| 237 |
|
| 238 |
self._draw_rounded_rect(
|
| 239 |
draw,
|
|
|
|
| 221 |
# Draw heading with background (UPPERCASE)
|
| 222 |
if heading:
|
| 223 |
heading_upper = heading.upper() # Convert to UPPERCASE
|
| 224 |
+
# Get text bounding box - returns (left, top, right, bottom)
|
| 225 |
heading_bbox = draw.textbbox((0, 0), heading_upper, font=heading_font)
|
| 226 |
+
# The bbox includes font metrics offset
|
| 227 |
+
text_y_offset = heading_bbox[1] # Top offset from baseline
|
| 228 |
heading_width = heading_bbox[2] - heading_bbox[0]
|
| 229 |
heading_height = heading_bbox[3] - heading_bbox[1]
|
| 230 |
heading_x = (self.TARGET_WIDTH - heading_width) // 2
|
| 231 |
|
| 232 |
+
# Draw background - ALWAYS show when heading exists
|
| 233 |
+
show_bg = True
|
| 234 |
+
if heading_background and heading_background.get('enabled') is False:
|
| 235 |
+
show_bg = False
|
| 236 |
+
|
| 237 |
+
if show_bg:
|
| 238 |
+
# Get color from config or use default coral
|
| 239 |
+
if heading_background and heading_background.get('color'):
|
| 240 |
+
bg_color = self._parse_rgba(heading_background.get('color'))
|
| 241 |
+
else:
|
| 242 |
+
bg_color = (255, 109, 128, 242) # Default coral color with 95% opacity
|
| 243 |
|
| 244 |
+
# Background position - account for text_y_offset to align with actual text
|
| 245 |
+
actual_text_y = current_y + text_y_offset
|
| 246 |
bg_x1 = heading_x - heading_bg_padding
|
| 247 |
+
bg_y1 = actual_text_y - heading_bg_padding
|
| 248 |
bg_x2 = heading_x + heading_width + heading_bg_padding
|
| 249 |
+
bg_y2 = actual_text_y + heading_height + heading_bg_padding
|
| 250 |
|
| 251 |
self._draw_rounded_rect(
|
| 252 |
draw,
|
modules/text_story/services/renderer.py
CHANGED
|
@@ -26,12 +26,12 @@ CANVAS_HEIGHT = 1920
|
|
| 26 |
# - Small avatar next to other person's messages
|
| 27 |
|
| 28 |
LAYOUT = {
|
| 29 |
-
"top_margin":
|
| 30 |
-
"side_margin":
|
| 31 |
-
"chat_box_width":
|
| 32 |
-
"chat_box_radius": 35, # Rounded corners
|
| 33 |
"header_height": 100, # Header with avatar + name + status
|
| 34 |
-
"max_chat_height":
|
| 35 |
}
|
| 36 |
|
| 37 |
# Colors (Facebook Messenger - exact from screenshot)
|
|
@@ -261,12 +261,13 @@ class ChatRenderer:
|
|
| 261 |
font=self.font_small
|
| 262 |
)
|
| 263 |
|
| 264 |
-
# Icons on right (phone, video, info)
|
| 265 |
-
right_x = x_offset + LAYOUT["chat_box_width"] -
|
| 266 |
icon_y = y_start + 35
|
| 267 |
-
|
| 268 |
-
draw.
|
| 269 |
-
draw.
|
|
|
|
| 270 |
|
| 271 |
def _draw_bubble(self, draw: ImageDraw.Draw,
|
| 272 |
x: int, y: int,
|
|
|
|
| 26 |
# - Small avatar next to other person's messages
|
| 27 |
|
| 28 |
LAYOUT = {
|
| 29 |
+
"top_margin": 670, # 35% from top (1920 * 0.35)
|
| 30 |
+
"side_margin": 50, # More side margin (left/right)
|
| 31 |
+
"chat_box_width": 980, # Narrower card (1080 - 50*2)
|
| 32 |
+
"chat_box_radius": 35, # Rounded corners
|
| 33 |
"header_height": 100, # Header with avatar + name + status
|
| 34 |
+
"max_chat_height": 1100, # Maximum height of chat box
|
| 35 |
}
|
| 36 |
|
| 37 |
# Colors (Facebook Messenger - exact from screenshot)
|
|
|
|
| 261 |
font=self.font_small
|
| 262 |
)
|
| 263 |
|
| 264 |
+
# Icons on right (phone, video, info) - using Unicode symbols
|
| 265 |
+
right_x = x_offset + LAYOUT["chat_box_width"] - 100
|
| 266 |
icon_y = y_start + 35
|
| 267 |
+
# Use filled circles as icon placeholders (compatible with all fonts)
|
| 268 |
+
draw.ellipse([right_x, icon_y + 5, right_x + 22, icon_y + 27], fill=COLORS["text_blue"])
|
| 269 |
+
draw.ellipse([right_x + 35, icon_y + 5, right_x + 57, icon_y + 27], fill=COLORS["text_blue"])
|
| 270 |
+
draw.ellipse([right_x + 70, icon_y + 5, right_x + 92, icon_y + 27], fill=COLORS["text_blue"])
|
| 271 |
|
| 272 |
def _draw_bubble(self, draw: ImageDraw.Draw,
|
| 273 |
x: int, y: int,
|