ismdrobiul489 commited on
Commit
c8b39c5
·
1 Parent(s): cce7cd9

Update text layout: Heading at 40%, Fact text at 50% from top

Browse files
modules/fact_image/services/text_overlay.py CHANGED
@@ -34,8 +34,9 @@ class TextOverlay:
34
  LINE_SPACING = 1.3
35
 
36
  # Layout settings
37
- HEADING_TOP_PERCENT = 0.15 # Heading starts at 15% from top
38
- GAP_HEADING_TEXT = 80 # Gap between heading and fact text
 
39
 
40
  def __init__(self, font_path: Optional[str] = None):
41
  """
@@ -210,10 +211,12 @@ class TextOverlay:
210
  gap_between = self.GAP_HEADING_TEXT if heading else 0 # Gap between heading and text
211
  total_height = text_height + (heading_height + heading_bg_padding * 2 + gap_between if heading else 0)
212
 
213
- # Position content at TOP (not center) - heading starts at 15% from top
214
- start_y = int(self.TARGET_HEIGHT * self.HEADING_TOP_PERCENT)
 
 
215
 
216
- current_y = start_y
217
 
218
  # Draw heading with background (UPPERCASE)
219
  if heading:
@@ -250,6 +253,8 @@ class TextOverlay:
250
  current_y += heading_height + heading_bg_padding + gap_between
251
 
252
  # Draw fact text with shadow/outline
 
 
253
  text_x = (self.TARGET_WIDTH - text_width) // 2
254
 
255
  # Draw outline (multiple directions for thickness)
@@ -257,7 +262,7 @@ class TextOverlay:
257
  for dy in range(-outline_width, outline_width + 1):
258
  if dx != 0 or dy != 0:
259
  draw.multiline_text(
260
- (text_x + dx, current_y + dy),
261
  wrapped_text,
262
  font=text_font,
263
  fill=(0, 0, 0, 200),
@@ -266,7 +271,7 @@ class TextOverlay:
266
 
267
  # Draw shadow
268
  draw.multiline_text(
269
- (text_x + shadow_offset, current_y + shadow_offset),
270
  wrapped_text,
271
  font=text_font,
272
  fill=(0, 0, 0, 150),
@@ -275,7 +280,7 @@ class TextOverlay:
275
 
276
  # Draw main text
277
  draw.multiline_text(
278
- (text_x, current_y),
279
  wrapped_text,
280
  font=text_font,
281
  fill=(255, 255, 255, 255),
 
34
  LINE_SPACING = 1.3
35
 
36
  # Layout settings
37
+ HEADING_TOP_PERCENT = 0.40 # Heading starts at 40% from top
38
+ TEXT_TOP_PERCENT = 0.50 # Fact text starts at 50% from top
39
+ GAP_HEADING_TEXT = 80 # Gap between heading and fact text (fallback)
40
 
41
  def __init__(self, font_path: Optional[str] = None):
42
  """
 
211
  gap_between = self.GAP_HEADING_TEXT if heading else 0 # Gap between heading and text
212
  total_height = text_height + (heading_height + heading_bg_padding * 2 + gap_between if heading else 0)
213
 
214
+ # Position heading at 40% from top
215
+ heading_y = int(self.TARGET_HEIGHT * self.HEADING_TOP_PERCENT)
216
+ # Position fact text at 50% from top
217
+ text_y = int(self.TARGET_HEIGHT * self.TEXT_TOP_PERCENT)
218
 
219
+ current_y = heading_y
220
 
221
  # Draw heading with background (UPPERCASE)
222
  if heading:
 
253
  current_y += heading_height + heading_bg_padding + gap_between
254
 
255
  # Draw fact text with shadow/outline
256
+ # Use fixed position at 50% from top
257
+ fact_text_y = text_y if heading else int(self.TARGET_HEIGHT * 0.40)
258
  text_x = (self.TARGET_WIDTH - text_width) // 2
259
 
260
  # Draw outline (multiple directions for thickness)
 
262
  for dy in range(-outline_width, outline_width + 1):
263
  if dx != 0 or dy != 0:
264
  draw.multiline_text(
265
+ (text_x + dx, fact_text_y + dy),
266
  wrapped_text,
267
  font=text_font,
268
  fill=(0, 0, 0, 200),
 
271
 
272
  # Draw shadow
273
  draw.multiline_text(
274
+ (text_x + shadow_offset, fact_text_y + shadow_offset),
275
  wrapped_text,
276
  font=text_font,
277
  fill=(0, 0, 0, 150),
 
280
 
281
  # Draw main text
282
  draw.multiline_text(
283
+ (text_x, fact_text_y),
284
  wrapped_text,
285
  font=text_font,
286
  fill=(255, 255, 255, 255),