aiqtech commited on
Commit
1fd13a0
·
verified ·
1 Parent(s): 0205c92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -10
app.py CHANGED
@@ -597,10 +597,6 @@ def add_text_to_image(
597
  if image.mode != 'RGBA':
598
  image = image.convert('RGBA')
599
 
600
- # 텍스트 오버레이 생성
601
- txt_overlay = Image.new('RGBA', image.size, (255, 255, 255, 0))
602
- draw = ImageDraw.Draw(txt_overlay)
603
-
604
  # 폰트 설정
605
  font_files = {
606
  "Default": "DejaVuSans.ttf",
@@ -639,14 +635,19 @@ def add_text_to_image(
639
  text_color = (*rgb_color, int(opacity))
640
 
641
  if text_position_type == "Text Behind Image":
642
- # 배경 제거된 이미지 생성
643
  foreground = remove_background(image)
644
 
645
- # 텍스트를 먼저 그리기
646
- background = Image.new('RGBA', image.size, (255, 255, 255, 0))
647
- draw_bg = ImageDraw.Draw(background)
 
 
 
 
 
648
  add_text_with_stroke(
649
- draw_bg,
650
  text,
651
  actual_x,
652
  actual_y,
@@ -655,9 +656,16 @@ def add_text_to_image(
655
  int(thickness)
656
  )
657
 
658
- # 텍스트 위에 배경 제거된 이미지 합성
 
 
 
659
  output_image = Image.alpha_composite(background, foreground)
660
  else:
 
 
 
 
661
  # 텍스트를 이미지 위에 그리기
662
  add_text_with_stroke(
663
  draw,
 
597
  if image.mode != 'RGBA':
598
  image = image.convert('RGBA')
599
 
 
 
 
 
600
  # 폰트 설정
601
  font_files = {
602
  "Default": "DejaVuSans.ttf",
 
635
  text_color = (*rgb_color, int(opacity))
636
 
637
  if text_position_type == "Text Behind Image":
638
+ # 원본 이미지에서 전경 객체만 추출
639
  foreground = remove_background(image)
640
 
641
+ # 배경 이미지 생성 (원본 이미지 복사)
642
+ background = image.copy()
643
+
644
+ # 텍스트를 그릴 임시 레이어 생성
645
+ text_layer = Image.new('RGBA', image.size, (255, 255, 255, 0))
646
+ draw_text = ImageDraw.Draw(text_layer)
647
+
648
+ # 텍스트 그리기
649
  add_text_with_stroke(
650
+ draw_text,
651
  text,
652
  actual_x,
653
  actual_y,
 
656
  int(thickness)
657
  )
658
 
659
+ # 배경에 텍스트 합성
660
+ background = Image.alpha_composite(background, text_layer)
661
+
662
+ # 텍스트가 있는 배경 위에 전경 객체 합성
663
  output_image = Image.alpha_composite(background, foreground)
664
  else:
665
+ # 텍스트 오버레이 생성
666
+ txt_overlay = Image.new('RGBA', image.size, (255, 255, 255, 0))
667
+ draw = ImageDraw.Draw(txt_overlay)
668
+
669
  # 텍스트를 이미지 위에 그리기
670
  add_text_with_stroke(
671
  draw,