Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -596,17 +596,9 @@ def add_text_to_image(
|
|
596 |
print(f"Unexpected image type: {type(input_image)}")
|
597 |
return input_image
|
598 |
|
599 |
-
# ์ด๋ฏธ์ง๋ฅผ RGBA ๋ชจ๋๋ก ๋ณํ
|
600 |
image = image.convert('RGBA')
|
601 |
-
|
602 |
-
# Text Behind Image ์ฒ๋ฆฌ
|
603 |
-
if text_position_type == "Text Behind Image":
|
604 |
-
try:
|
605 |
-
overlay_image = remove_background(image)
|
606 |
-
except Exception as e:
|
607 |
-
print(f"Background removal failed: {str(e)}")
|
608 |
-
overlay_image = image
|
609 |
-
|
610 |
# ํ
์คํธ ์ค๋ฒ๋ ์ด ์์ฑ
|
611 |
txt_overlay = Image.new('RGBA', image.size, (255, 255, 255, 0))
|
612 |
draw = ImageDraw.Draw(txt_overlay)
|
@@ -646,24 +638,42 @@ def add_text_to_image(
|
|
646 |
# ํ
์คํธ ์์ ์ค์ (ํฌ๋ช
๋ ํฌํจ)
|
647 |
text_color = (*rgb_color, int(opacity))
|
648 |
|
649 |
-
# ํ
์คํธ ๊ทธ๋ฆฌ๊ธฐ (์ธ๊ณฝ์ ํฌํจ)
|
650 |
-
for dx in range(-thickness, thickness + 1):
|
651 |
-
for dy in range(-thickness, thickness + 1):
|
652 |
-
draw.text(
|
653 |
-
(actual_x + dx, actual_y + dy),
|
654 |
-
text,
|
655 |
-
font=font,
|
656 |
-
fill=text_color
|
657 |
-
)
|
658 |
-
|
659 |
-
# ์ต์ข
์ด๋ฏธ์ง ํฉ์ฑ
|
660 |
if text_position_type == "Text Behind Image":
|
661 |
-
#
|
662 |
-
|
663 |
-
|
664 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
665 |
else:
|
666 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
667 |
output_image = Image.alpha_composite(image, txt_overlay)
|
668 |
|
669 |
# RGB๋ก ๋ณํํ์ฌ ๋ฐํ
|
@@ -673,8 +683,6 @@ def add_text_to_image(
|
|
673 |
print(f"Text addition error: {str(e)}")
|
674 |
return input_image
|
675 |
|
676 |
-
|
677 |
-
|
678 |
|
679 |
def update_position(new_position):
|
680 |
"""์์น ์
๋ฐ์ดํธ ํจ์"""
|
|
|
596 |
print(f"Unexpected image type: {type(input_image)}")
|
597 |
return input_image
|
598 |
|
599 |
+
# ์๋ณธ ์ด๋ฏธ์ง๋ฅผ RGBA ๋ชจ๋๋ก ๋ณํ
|
600 |
image = image.convert('RGBA')
|
601 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
602 |
# ํ
์คํธ ์ค๋ฒ๋ ์ด ์์ฑ
|
603 |
txt_overlay = Image.new('RGBA', image.size, (255, 255, 255, 0))
|
604 |
draw = ImageDraw.Draw(txt_overlay)
|
|
|
638 |
# ํ
์คํธ ์์ ์ค์ (ํฌ๋ช
๋ ํฌํจ)
|
639 |
text_color = (*rgb_color, int(opacity))
|
640 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
641 |
if text_position_type == "Text Behind Image":
|
642 |
+
# 1. ์๋ณธ ์ด๋ฏธ์ง์์ ํฌ๋ช
ํ ๋ถ๋ถ ์ถ์ถ
|
643 |
+
alpha_mask = image.split()[3] if len(image.split()) == 4 else None
|
644 |
+
|
645 |
+
# 2. ํ
์คํธ๋ฅผ ๋จผ์ ๊ทธ๋ฆฌ๊ธฐ
|
646 |
+
background = Image.new('RGBA', image.size, (255, 255, 255, 0))
|
647 |
+
text_layer = Image.new('RGBA', image.size, (255, 255, 255, 0))
|
648 |
+
text_draw = ImageDraw.Draw(text_layer)
|
649 |
+
|
650 |
+
# ํ
์คํธ ๊ทธ๋ฆฌ๊ธฐ (์ธ๊ณฝ์ ํฌํจ)
|
651 |
+
for dx in range(-thickness, thickness + 1):
|
652 |
+
for dy in range(-thickness, thickness + 1):
|
653 |
+
text_draw.text(
|
654 |
+
(actual_x + dx, actual_y + dy),
|
655 |
+
text,
|
656 |
+
font=font,
|
657 |
+
fill=text_color
|
658 |
+
)
|
659 |
+
|
660 |
+
# 3. ์ด๋ฏธ์ง ํฉ์ฑ
|
661 |
+
if alpha_mask:
|
662 |
+
# ์๋ณธ ์ด๋ฏธ์ง์ ํฌ๋ช
ํ์ง ์์ ๋ถ๋ถ๋ง ์ ์ง
|
663 |
+
output_image = Image.alpha_composite(text_layer, image)
|
664 |
+
else:
|
665 |
+
# ์ํ ์ฑ๋์ด ์๋ ๊ฒฝ์ฐ
|
666 |
+
output_image = Image.alpha_composite(text_layer, image)
|
667 |
else:
|
668 |
+
# Text Over Image - ๊ธฐ์กด ๋ฐฉ์๋๋ก ์ฒ๋ฆฌ
|
669 |
+
for dx in range(-thickness, thickness + 1):
|
670 |
+
for dy in range(-thickness, thickness + 1):
|
671 |
+
draw.text(
|
672 |
+
(actual_x + dx, actual_y + dy),
|
673 |
+
text,
|
674 |
+
font=font,
|
675 |
+
fill=text_color
|
676 |
+
)
|
677 |
output_image = Image.alpha_composite(image, txt_overlay)
|
678 |
|
679 |
# RGB๋ก ๋ณํํ์ฌ ๋ฐํ
|
|
|
683 |
print(f"Text addition error: {str(e)}")
|
684 |
return input_image
|
685 |
|
|
|
|
|
686 |
|
687 |
def update_position(new_position):
|
688 |
"""์์น ์
๋ฐ์ดํธ ํจ์"""
|