ismdrobiul489 commited on
Commit
8c58782
·
1 Parent(s): 59fe149

Major layout update: heading 80px uppercase at top 15%, fact text 60px bold, 80px gap

Browse files
modules/fact_image/services/text_overlay.py CHANGED
@@ -29,10 +29,14 @@ class TextOverlay:
29
  PADDING_X = 60 # Horizontal padding
30
 
31
  # Font sizes
32
- HEADING_FONT_SIZE = 65
33
- TEXT_FONT_SIZE = 53
34
  LINE_SPACING = 1.3
35
 
 
 
 
 
36
  def __init__(self, font_path: Optional[str] = None):
37
  """
38
  Initialize text overlay service.
@@ -172,9 +176,9 @@ class TextOverlay:
172
  overlay = Image.new('RGBA', img.size, (0, 0, 0, 0))
173
  draw = ImageDraw.Draw(overlay)
174
 
175
- # Get fonts
176
  heading_font = self._get_font(self.HEADING_FONT_SIZE, bold=True)
177
- text_font = self._get_font(self.TEXT_FONT_SIZE, bold=False)
178
 
179
  # Calculate max width
180
  max_width = self.TARGET_WIDTH - (2 * self.PADDING_X)
@@ -203,16 +207,20 @@ class TextOverlay:
203
  heading_bg_radius = heading_background.get('corner_radius', 28)
204
 
205
  # Calculate total content height
206
- gap_between = 40 if heading else 0 # Gap between heading and text
207
  total_height = text_height + (heading_height + heading_bg_padding * 2 + gap_between if heading else 0)
208
 
209
- # Center everything vertically in the middle of the image
210
- start_y = (self.TARGET_HEIGHT - total_height) // 2
211
 
212
  current_y = start_y
213
 
214
- # Draw heading with background
215
  if heading:
 
 
 
 
216
  heading_x = (self.TARGET_WIDTH - heading_width) // 2
217
 
218
  # Draw background if enabled
@@ -231,10 +239,10 @@ class TextOverlay:
231
  bg_color
232
  )
233
 
234
- # Draw heading text (white)
235
  draw.text(
236
  (heading_x, current_y),
237
- heading,
238
  font=heading_font,
239
  fill=(255, 255, 255, 255)
240
  )
 
29
  PADDING_X = 60 # Horizontal padding
30
 
31
  # Font sizes
32
+ HEADING_FONT_SIZE = 80
33
+ TEXT_FONT_SIZE = 60
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
  """
42
  Initialize text overlay service.
 
176
  overlay = Image.new('RGBA', img.size, (0, 0, 0, 0))
177
  draw = ImageDraw.Draw(overlay)
178
 
179
+ # Get fonts (both bold now)
180
  heading_font = self._get_font(self.HEADING_FONT_SIZE, bold=True)
181
+ text_font = self._get_font(self.TEXT_FONT_SIZE, bold=True) # Fact text also bold
182
 
183
  # Calculate max width
184
  max_width = self.TARGET_WIDTH - (2 * self.PADDING_X)
 
207
  heading_bg_radius = heading_background.get('corner_radius', 28)
208
 
209
  # Calculate total content height
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:
220
+ heading_upper = heading.upper() # Convert to UPPERCASE
221
+ heading_bbox = draw.textbbox((0, 0), heading_upper, font=heading_font)
222
+ heading_width = heading_bbox[2] - heading_bbox[0]
223
+ heading_height = heading_bbox[3] - heading_bbox[1]
224
  heading_x = (self.TARGET_WIDTH - heading_width) // 2
225
 
226
  # Draw background if enabled
 
239
  bg_color
240
  )
241
 
242
+ # Draw heading text (white, UPPERCASE)
243
  draw.text(
244
  (heading_x, current_y),
245
+ heading_upper,
246
  font=heading_font,
247
  fill=(255, 255, 255, 255)
248
  )