aiqtech commited on
Commit
528d64e
·
verified ·
1 Parent(s): 0143edd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -5
app.py CHANGED
@@ -525,7 +525,8 @@ def add_text_to_image(
525
  x_position,
526
  y_position,
527
  thickness,
528
- text_position_type
 
529
  ):
530
  """
531
  Add text to an image with customizable properties
@@ -557,9 +558,17 @@ def add_text_to_image(
557
  draw = ImageDraw.Draw(txt_overlay)
558
 
559
  # 폰트 설정
 
 
 
 
 
 
560
  try:
561
- font = ImageFont.truetype("DejaVuSans.ttf", int(font_size))
562
- except:
 
 
563
  try:
564
  font = ImageFont.truetype("arial.ttf", int(font_size))
565
  except:
@@ -617,6 +626,7 @@ def add_text_to_image(
617
  except Exception as e:
618
  print(f"Error in add_text_to_image: {str(e)}")
619
  return input_image
 
620
 
621
  with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
622
  gr.HTML("""
@@ -710,6 +720,13 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
710
 
711
  with gr.Row():
712
  with gr.Column(scale=1):
 
 
 
 
 
 
 
713
  font_size = gr.Slider(
714
  minimum=10,
715
  maximum=200,
@@ -819,7 +836,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
819
  queue=True
820
  )
821
 
822
- # 텍스트 추가 버튼 이벤트 연결
823
  add_text_btn.click(
824
  fn=add_text_to_image,
825
  inputs=[
@@ -831,7 +848,8 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
831
  x_position,
832
  y_position,
833
  thickness,
834
- text_position_type
 
835
  ],
836
  outputs=combined_image
837
  )
 
525
  x_position,
526
  y_position,
527
  thickness,
528
+ text_position_type,
529
+ font_choice # 새로운 파라미터 추가
530
  ):
531
  """
532
  Add text to an image with customizable properties
 
558
  draw = ImageDraw.Draw(txt_overlay)
559
 
560
  # 폰트 설정
561
+ font_files = {
562
+ "Default": "DejaVuSans.ttf",
563
+ "Korean Regular": "ko-Regular.ttf",
564
+ "Korean Son": "ko-son.ttf"
565
+ }
566
+
567
  try:
568
+ font_file = font_files.get(font_choice, "DejaVuSans.ttf")
569
+ font = ImageFont.truetype(font_file, int(font_size))
570
+ except Exception as e:
571
+ print(f"Font loading error ({font_choice}): {str(e)}")
572
  try:
573
  font = ImageFont.truetype("arial.ttf", int(font_size))
574
  except:
 
626
  except Exception as e:
627
  print(f"Error in add_text_to_image: {str(e)}")
628
  return input_image
629
+
630
 
631
  with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
632
  gr.HTML("""
 
720
 
721
  with gr.Row():
722
  with gr.Column(scale=1):
723
+ # 폰트 선택 Dropdown 추가
724
+ font_choice = gr.Dropdown(
725
+ choices=["Default", "Korean Regular", "Korean Son"],
726
+ value="Default",
727
+ label="Font Selection",
728
+ interactive=True
729
+ )
730
  font_size = gr.Slider(
731
  minimum=10,
732
  maximum=200,
 
836
  queue=True
837
  )
838
 
839
+ # 텍스트 추가 버튼 이벤트 연결 수정
840
  add_text_btn.click(
841
  fn=add_text_to_image,
842
  inputs=[
 
848
  x_position,
849
  y_position,
850
  thickness,
851
+ text_position_type,
852
+ font_choice # 새로운 입력 추가
853
  ],
854
  outputs=combined_image
855
  )