RozzaCreat commited on
Commit
b4e3e0c
·
verified ·
1 Parent(s): 1adc3da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -28
app.py CHANGED
@@ -39,14 +39,14 @@ def generate_passover_coloring_pages(age):
39
  ],
40
  "intermediate": [
41
  "Jewish Seder table with symbolic foods",
42
- "Hebrew letters spelling 'Pesach'",
43
  "Israelites leaving Egypt scene",
44
  "Four Sons from the Haggadah"
45
  ],
46
  "advanced": [
47
  "Haggadah page with Seder order",
48
  "Miriam and women celebrating after Red Sea",
49
- "Hebrew calligraphy 'Next year in Jerusalem'",
50
  "Passover journey from slavery to freedom"
51
  ]
52
  }
@@ -58,24 +58,19 @@ def generate_passover_coloring_pages(age):
58
  temp_dir = os.path.join(IMAGES_DIR, f"temp_{timestamp}")
59
  os.makedirs(temp_dir, exist_ok=True)
60
 
61
- # Load font
62
- try:
63
- font = ImageFont.truetype("Arial", 40)
64
- small_font = ImageFont.truetype("Arial", 20)
65
- except:
66
- font = ImageFont.load_default()
67
- small_font = ImageFont.load_default()
68
 
69
  # Create a cover page
70
  cover_img = Image.new('RGB', (2480, 3508), color='white') # A4 size at 300 DPI
71
  draw = ImageDraw.Draw(cover_img)
72
 
73
- # Add title to cover page
74
- draw.text((1240, 800), "Jewish Passover (Pesach)", fill='black', anchor='mm', font=font)
75
- draw.text((1240, 1000), "Coloring Pages", fill='black', anchor='mm', font=font)
76
- draw.text((1240, 1200), f"For Ages {age} Years", fill='black', anchor='mm', font=font)
77
- draw.text((1240, 1500), "Created for Jewish children and families", fill='black', anchor='mm', font=small_font)
78
- draw.text((1240, 1600), "to celebrate the story of Passover", fill='black', anchor='mm', font=small_font)
79
 
80
  # Save cover page
81
  cover_path = os.path.join(temp_dir, f"01_cover.png")
@@ -92,7 +87,7 @@ def generate_passover_coloring_pages(age):
92
  draw.rectangle([(100, 100), (2380, 3408)], outline='black', width=4)
93
 
94
  # Add title at the top
95
- draw.text((1240, 200), description, fill='black', anchor='mm', font=font)
96
 
97
  # Add a content area for the coloring image
98
  draw.rectangle([(300, 400), (2180, 2800)], outline='black', width=2)
@@ -116,7 +111,7 @@ def generate_passover_coloring_pages(age):
116
  sections = ["Karpas", "Charoset", "Maror", "Zeroa", "Beitzah", "Chazeret"]
117
  positions = [(975, 1075), (1525, 1075), (975, 1625), (1525, 1625), (1250, 1075), (1250, 1625)]
118
  for section, pos in zip(sections, positions):
119
- draw.text(pos, section, fill='black', anchor='mm', font=small_font)
120
 
121
  elif "red sea" in description.lower():
122
  # Draw the Red Sea
@@ -134,21 +129,24 @@ def generate_passover_coloring_pages(age):
134
  draw.rectangle([(1050, 600), (1350, 2600)], outline='black', width=3)
135
 
136
  elif "hebrew" in description.lower() and "pesach" in description.lower():
137
- # Draw Hebrew for Pesach
138
- # פ
139
- draw.text((900, 1400), "פ", fill='black', font=ImageFont.truetype("Arial", 400) if font != ImageFont.load_default() else font)
140
- # ס
141
- draw.text((1200, 1400), "ס", fill='black', font=ImageFont.truetype("Arial", 400) if font != ImageFont.load_default() else font)
142
- # ח
143
- draw.text((1500, 1400), "ח", fill='black', font=ImageFont.truetype("Arial", 400) if font != ImageFont.load_default() else font)
 
 
 
144
 
145
  # Add description
146
- draw.text((1240, 1600), description, fill='black', anchor='mm', font=small_font)
147
- draw.text((1240, 1700), "Jewish Passover Coloring Page", fill='black', anchor='mm', font=small_font)
148
- draw.text((1240, 1800), f"For age: {age}", fill='black', anchor='mm', font=small_font)
149
 
150
  # Add footer
151
- draw.text((1240, 3300), f"Page {i+1} of {len(selected_pages)}", fill='black', anchor='mm', font=small_font)
152
 
153
  # Save with sequential numbering for proper PDF ordering
154
  seq_num = i + 2 # Start from 2 after the cover page
@@ -297,6 +295,23 @@ def generate_passover_coloring_pages(age):
297
 
298
  return html_path
299
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
  if __name__ == "__main__":
301
  print("===== Jewish Passover Coloring Pages Generator =====")
302
 
 
39
  ],
40
  "intermediate": [
41
  "Jewish Seder table with symbolic foods",
42
+ "Hebrew letters spelling Pesach",
43
  "Israelites leaving Egypt scene",
44
  "Four Sons from the Haggadah"
45
  ],
46
  "advanced": [
47
  "Haggadah page with Seder order",
48
  "Miriam and women celebrating after Red Sea",
49
+ "Hebrew calligraphy Next year in Jerusalem",
50
  "Passover journey from slavery to freedom"
51
  ]
52
  }
 
58
  temp_dir = os.path.join(IMAGES_DIR, f"temp_{timestamp}")
59
  os.makedirs(temp_dir, exist_ok=True)
60
 
61
+ # Always use default font to avoid font loading issues
62
+ font = ImageFont.load_default()
 
 
 
 
 
63
 
64
  # Create a cover page
65
  cover_img = Image.new('RGB', (2480, 3508), color='white') # A4 size at 300 DPI
66
  draw = ImageDraw.Draw(cover_img)
67
 
68
+ # Add title to cover page - using simple text placement
69
+ draw_centered_text(draw, "Jewish Passover (Pesach)", 1240, 800, font)
70
+ draw_centered_text(draw, "Coloring Pages", 1240, 1000, font)
71
+ draw_centered_text(draw, f"For Ages {age} Years", 1240, 1200, font)
72
+ draw_centered_text(draw, "Created for Jewish children and families", 1240, 1500, font)
73
+ draw_centered_text(draw, "to celebrate the story of Passover", 1240, 1600, font)
74
 
75
  # Save cover page
76
  cover_path = os.path.join(temp_dir, f"01_cover.png")
 
87
  draw.rectangle([(100, 100), (2380, 3408)], outline='black', width=4)
88
 
89
  # Add title at the top
90
+ draw_centered_text(draw, description, 1240, 200, font)
91
 
92
  # Add a content area for the coloring image
93
  draw.rectangle([(300, 400), (2180, 2800)], outline='black', width=2)
 
111
  sections = ["Karpas", "Charoset", "Maror", "Zeroa", "Beitzah", "Chazeret"]
112
  positions = [(975, 1075), (1525, 1075), (975, 1625), (1525, 1625), (1250, 1075), (1250, 1625)]
113
  for section, pos in zip(sections, positions):
114
+ draw_centered_text(draw, section, pos[0], pos[1], font)
115
 
116
  elif "red sea" in description.lower():
117
  # Draw the Red Sea
 
129
  draw.rectangle([(1050, 600), (1350, 2600)], outline='black', width=3)
130
 
131
  elif "hebrew" in description.lower() and "pesach" in description.lower():
132
+ # Draw a simple symbol instead of Hebrew text to avoid font issues
133
+ draw.rectangle([(900, 1300), (1100, 1500)], outline='black', width=3)
134
+ draw.rectangle([(1200, 1300), (1400, 1500)], outline='black', width=3)
135
+ draw.rectangle([(1500, 1300), (1700, 1500)], outline='black', width=3)
136
+
137
+ # Add text labels
138
+ draw_centered_text(draw, "P", 1000, 1400, font)
139
+ draw_centered_text(draw, "E", 1300, 1400, font)
140
+ draw_centered_text(draw, "S", 1600, 1400, font)
141
+ draw_centered_text(draw, "PESACH", 1300, 1600, font)
142
 
143
  # Add description
144
+ draw_centered_text(draw, description, 1240, 1600, font)
145
+ draw_centered_text(draw, "Jewish Passover Coloring Page", 1240, 1700, font)
146
+ draw_centered_text(draw, f"For age: {age}", 1240, 1800, font)
147
 
148
  # Add footer
149
+ draw_centered_text(draw, f"Page {i+1} of {len(selected_pages)}", 1240, 3300, font)
150
 
151
  # Save with sequential numbering for proper PDF ordering
152
  seq_num = i + 2 # Start from 2 after the cover page
 
295
 
296
  return html_path
297
 
298
+ # Helper function to draw centered text without relying on font-specific anchor points
299
+ def draw_centered_text(draw, text, x, y, font):
300
+ # Get the text size
301
+ try:
302
+ text_width, text_height = draw.textsize(text, font=font)
303
+ except:
304
+ # Estimate text size for older PIL versions or if textsize fails
305
+ text_width = len(text) * 7 # Rough estimate
306
+ text_height = 12
307
+
308
+ # Calculate position for centered text
309
+ text_x = x - (text_width // 2)
310
+ text_y = y - (text_height // 2)
311
+
312
+ # Draw the text
313
+ draw.text((text_x, text_y), text, fill='black', font=font)
314
+
315
  if __name__ == "__main__":
316
  print("===== Jewish Passover Coloring Pages Generator =====")
317