Skip to content

Commit

Permalink
שיפור עיצוב וסגנון
Browse files Browse the repository at this point in the history
  • Loading branch information
NHLOCAL committed Oct 27, 2024
1 parent d303fa4 commit d2bf2d2
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 20 deletions.
File renamed without changes.
Binary file added assets/fonts/arialbd.ttf
Binary file not shown.
101 changes: 81 additions & 20 deletions scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@
# נתיבים לקבצים
JSON_FILE = os.path.join(DATA_DIR, 'words.json')
FONT_PATH = os.path.join(FONTS_DIR, 'arial.ttf') # ודא שהגופן תומך בעברית
SUBTOPIC_FONT_PATH = os.path.join(FONTS_DIR, 'arialbd.ttf') # גופן מודגש עבור Subtopics
LOGO_PATH = os.path.join(LOGOS_DIR, 'logo.png') # אם תרצה להשתמש בלוגו

# הגדרות עיצוב
FONT_SIZE = 48
FONT_SIZE = 80 # הגדלת גודל הגופן למילים ולמשפטים
SUBTOPIC_FONT_SIZE = 100 # גודל גופן שונה ל-Subtopics
LEVEL_FONT_SIZE = 120 # גודל גופן למסך פתיחת Level
BG_COLOR = (255, 255, 255) # רקע לבן
TEXT_COLOR = (0, 0, 0) # טקסט שחור
DURATION_PER_CLIP = 3 # משך כל קליפ בשניות
SUBTOPIC_BG_COLOR = (200, 200, 255) # רקע שונה ל-Subtopics
LEVEL_BG_COLOR = (255, 223, 186) # רקע מיוחד למסך פתיחת Level
TEXT_COLOR = (0, 0, 0) # טקסט שחור
SUBTOPIC_TEXT_COLOR = (0, 0, 128) # צבע טקסט שונה ל-Subtopics
LEVEL_TEXT_COLOR = (255, 69, 0) # צבע טקסט שונה למסך פתיחת Level
DURATION_PER_CLIP = 3 # משך כל קליפ בשניות
DELAY_BETWEEN_CLIPS = 1 # משך ההמתנה בין קליפים בשניות

# ודא שתיקיות היצוא זמינות
os.makedirs(OUTPUT_DIR, exist_ok=True)
Expand All @@ -48,32 +56,53 @@ def process_hebrew_text(text):
return bidi_text

# פונקציה ליצירת תמונת רקע עם טקסט
def create_image(text_lines, image_path):
def create_image(text_lines, image_path, style='normal'):
# בחירת צבע רקע ועיצוב לפי הסגנון
if style == 'subtopic':
bg_color = SUBTOPIC_BG_COLOR
text_color = SUBTOPIC_TEXT_COLOR
font_size = SUBTOPIC_FONT_SIZE
font_path = SUBTOPIC_FONT_PATH
elif style == 'level':
bg_color = LEVEL_BG_COLOR
text_color = LEVEL_TEXT_COLOR
font_size = LEVEL_FONT_SIZE
font_path = SUBTOPIC_FONT_PATH # שימוש בגופן מודגש
else:
bg_color = BG_COLOR
text_color = TEXT_COLOR
font_size = FONT_SIZE
font_path = FONT_PATH

# יצירת תמונה
img = Image.new('RGB', (1920, 1080), color=BG_COLOR)
img = Image.new('RGB', (1920, 1080), color=bg_color)
draw = ImageDraw.Draw(img)
try:
font = ImageFont.truetype(FONT_PATH, FONT_SIZE)
font = ImageFont.truetype(font_path, font_size)
except IOError:
print(f"לא ניתן למצוא את הגופן בנתיב: {FONT_PATH}")
print(f"לא ניתן למצוא את הגופן בנתיב: {font_path}")
raise

# חישוב מיקום הטקסט
y_text = 50
# חישוב מיקום הטקסט במרכז האנכי והאופקי
total_height = 0
processed_lines = []
for line in text_lines:
# בדיקה אם הטקסט בעברית
if is_hebrew(line):
# עיבוד הטקסט עבור עברית
processed_line = process_hebrew_text(line)
else:
processed_line = line

bbox = draw.textbbox((0, 0), processed_line, font=font)
width = bbox[2] - bbox[0]
height = bbox[3] - bbox[1]
x_text = (img.width - width) / 2
draw.text((x_text, y_text), processed_line, font=font, fill=TEXT_COLOR)
y_text += height + 20 # רווח בין השורות
processed_lines.append((processed_line, width, height))
total_height += height + 40 # רווח גדול יותר בין השורות

current_y = (img.height - total_height) / 2 # מרכז אנכי

for processed_line, width, height in processed_lines:
x_text = (img.width - width) / 2 # מרכז אופקי
draw.text((x_text, current_y), processed_line, font=font, fill=text_color)
current_y += height + 40 # רווח בין השורות

# שמירת התמונה
img.save(image_path)
Expand All @@ -98,6 +127,22 @@ def create_clip(image_path, audio_en_path, audio_he_path):
img_clip = img_clip.set_audio(audio_total)
return img_clip

# פונקציה ליצירת מסך פתיחה לכל Level
def create_level_intro(level_num, level_name):
intro_image_path = os.path.join(TEMP_DIR, f"level_{level_num}_intro.png")
text_lines_intro = [f"Level {level_num}", level_name]
create_image(text_lines_intro, intro_image_path, style='level')

# יצירת אודיו לפתיחת Level
audio_intro_en = os.path.join(TEMP_DIR, f"level_{level_num}_intro_en.mp3")
audio_intro_he = os.path.join(TEMP_DIR, f"level_{level_num}_intro_he.mp3")
create_audio(f"Level {level_num}", 'en', audio_intro_en)
create_audio(level_name, 'iw', audio_intro_he)

# יצירת קליפ פתיחה
clip_intro = create_clip(intro_image_path, audio_intro_en, audio_intro_he)
return clip_intro

# לולאה דרך כל הרמות
for level in data['levels']:
level_num = level['level']
Expand All @@ -112,15 +157,23 @@ def create_clip(image_path, audio_en_path, audio_he_path):
# רשימה לאחסון הקליפים
clips = []

# יצירת קליפ פתיחה ל-Level
clip_level_intro = create_level_intro(level_num, level_name)
clips.append(clip_level_intro)

# יצירת השהייה אחרי פתיחת Level
blank_clip = ColorClip(size=(1920, 1080), color=BG_COLOR, duration=DELAY_BETWEEN_CLIPS)
clips.append(blank_clip)

for subtopic in level['subtopics']:
subtopic_name = subtopic['name']
print(f" מעבד Subtopic: {subtopic_name}")

# יצירת כותרת Subtopic
# יצירת כותרת Subtopic עם עיצוב ייחודי
safe_subtopic_name = "".join([c for c in subtopic_name if c.isalnum() or c in (' ', '_')]).rstrip().replace(" ", "_")
image_subtopic_path = os.path.join(TEMP_DIR, f"{safe_level_name}_subtopic_{safe_subtopic_name}.png")
text_lines_subtopic = [subtopic_name]
create_image(text_lines_subtopic, image_subtopic_path)
create_image(text_lines_subtopic, image_subtopic_path, style='subtopic')

# יצירת אודיו Subtopic
audio_subtopic_en = os.path.join(TEMP_DIR, f"{safe_level_name}_subtopic_{safe_subtopic_name}_en.mp3")
Expand All @@ -132,6 +185,9 @@ def create_clip(image_path, audio_en_path, audio_he_path):
clip_subtopic = create_clip(image_subtopic_path, audio_subtopic_en, audio_subtopic_he)
clips.append(clip_subtopic)

# יצירת השהייה אחרי Subtopic
clips.append(blank_clip)

for word in subtopic['words']:
word_text = word['word']
word_translation = word['translation']
Expand All @@ -143,7 +199,7 @@ def create_clip(image_path, audio_en_path, audio_he_path):
safe_word_text = "".join([c for c in word_text if c.isalnum() or c in (' ', '_')]).rstrip().replace(" ", "_")
image_word_path = os.path.join(TEMP_DIR, f"{safe_level_name}_word_{safe_word_text}.png")
text_lines_word = [word_text, word_translation]
create_image(text_lines_word, image_word_path)
create_image(text_lines_word, image_word_path) # עיצוב רגיל

# יצירת אודיו למילה ולתרגום
audio_word_en = os.path.join(TEMP_DIR, f"{safe_level_name}_word_{safe_word_text}_en.mp3")
Expand All @@ -155,6 +211,9 @@ def create_clip(image_path, audio_en_path, audio_he_path):
clip_word = create_clip(image_word_path, audio_word_en, audio_word_he)
clips.append(clip_word)

# יצירת השהייה אחרי מילה
clips.append(blank_clip)

for idx, example in enumerate(examples):
sentence = example['sentence']
translation = example['translation']
Expand All @@ -165,7 +224,7 @@ def create_clip(image_path, audio_en_path, audio_he_path):
safe_sentence = "".join([c for c in sentence if c.isalnum() or c in (' ', '_')]).rstrip().replace(" ", "_")
image_example_path = os.path.join(TEMP_DIR, f"{safe_level_name}_word_{safe_word_text}_example_{idx+1}.png")
text_lines_example = [sentence, translation]
create_image(text_lines_example, image_example_path)
create_image(text_lines_example, image_example_path) # עיצוב רגיל

# יצירת אודיו למשפט ולתרגום
audio_example_en = os.path.join(TEMP_DIR, f"{safe_level_name}_word_{safe_word_text}_example_{idx+1}_en.mp3")
Expand All @@ -177,6 +236,9 @@ def create_clip(image_path, audio_en_path, audio_he_path):
clip_example = create_clip(image_example_path, audio_example_en, audio_example_he)
clips.append(clip_example)

# יצירת השהייה אחרי משפט
clips.append(blank_clip)

# ניקוי קבצים זמניים למשפט
os.remove(image_example_path)
os.remove(audio_example_en)
Expand All @@ -201,7 +263,6 @@ def create_clip(image_path, audio_en_path, audio_he_path):
final_clip.write_videofile(video_path, fps=24, codec='libx264', audio_codec='aac')

# ניקוי קבצים זמניים לאחר שמירת הוידאו
# אם ברצונך לשמור את הקבצים הזמניים, תוכל להסיר את החלק הזה
for temp_file in os.listdir(TEMP_DIR):
temp_file_path = os.path.join(TEMP_DIR, temp_file)
if os.path.isfile(temp_file_path):
Expand Down

0 comments on commit d2bf2d2

Please sign in to comment.