arxivgpt kim
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -49,20 +49,30 @@ def process(image, background_image=None):
|
|
49 |
|
50 |
return result_image
|
51 |
|
52 |
-
def merge_images(
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
54 |
foreground = foreground_image.convert("RGBA")
|
55 |
|
|
|
56 |
scale_factor = 0.3
|
57 |
new_size = (int(background.width * scale_factor), int(foreground.height * background.width / foreground.width * scale_factor))
|
58 |
foreground_resized = foreground.resize(new_size, Image.Resampling.LANCZOS)
|
59 |
|
|
|
60 |
x = (background.width - new_size[0]) // 2
|
61 |
y = (background.height - new_size[1]) // 2
|
62 |
|
|
|
63 |
background.paste(foreground_resized, (x, y), foreground_resized)
|
|
|
64 |
return background
|
65 |
|
|
|
66 |
# Gradio 인터페이스 정의
|
67 |
demo = gr.Interface(
|
68 |
fn=process,
|
|
|
49 |
|
50 |
return result_image
|
51 |
|
52 |
+
def merge_images(background_image, foreground_image):
|
53 |
+
"""
|
54 |
+
배경 이미지에 배경이 제거된 이미지를 투명하게 삽입합니다.
|
55 |
+
배경이 제거된 이미지는 배경 이미지 중앙에 30% 크기로 축소되어 삽입됩니다.
|
56 |
+
"""
|
57 |
+
# 이미 RGBA 모드로 변환된 이미지를 직접 사용합니다.
|
58 |
+
background = background_image.convert("RGBA")
|
59 |
foreground = foreground_image.convert("RGBA")
|
60 |
|
61 |
+
# 전경 이미지를 배경 이미지의 30% 크기로 조정
|
62 |
scale_factor = 0.3
|
63 |
new_size = (int(background.width * scale_factor), int(foreground.height * background.width / foreground.width * scale_factor))
|
64 |
foreground_resized = foreground.resize(new_size, Image.Resampling.LANCZOS)
|
65 |
|
66 |
+
# 전경 이미지를 배경 이미지의 가운데에 위치시키기 위한 좌표 계산
|
67 |
x = (background.width - new_size[0]) // 2
|
68 |
y = (background.height - new_size[1]) // 2
|
69 |
|
70 |
+
# 배경 이미지 위에 전경 이미지를 붙임
|
71 |
background.paste(foreground_resized, (x, y), foreground_resized)
|
72 |
+
|
73 |
return background
|
74 |
|
75 |
+
|
76 |
# Gradio 인터페이스 정의
|
77 |
demo = gr.Interface(
|
78 |
fn=process,
|