Spaces:
Running
Running
Commit
·
208c40c
1
Parent(s):
da190f1
Update app.py
Browse files
app.py
CHANGED
@@ -3,31 +3,35 @@ from PIL import Image, ImageOps
|
|
3 |
import gradio as gr
|
4 |
|
5 |
|
6 |
-
def change_color(passport='Passport Photo', color
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
26 |
|
27 |
|
28 |
inputs = [
|
29 |
gr.Image(label="Passport Photo", type="pil", image_mode="RGBA"),
|
30 |
gr.ColorPicker(label="Background Color",value="#ff00ff"),
|
|
|
31 |
]
|
32 |
outputs = gr.Image(label="Download Image")
|
33 |
|
|
|
3 |
import gradio as gr
|
4 |
|
5 |
|
6 |
+
def change_color(passport='Passport Photo', color='Background Color', background='Photo Background'):
|
7 |
+
if background:
|
8 |
+
image = remove(passport)
|
9 |
+
else:
|
10 |
+
image = passport
|
11 |
+
new_image = Image.new("RGB", image.size, color)
|
12 |
+
new_image.paste(image, mask=image)
|
13 |
+
# Add a black border of 10 pixels on all sides
|
14 |
+
new_image = ImageOps.expand(new_image, border=5, fill='black')
|
15 |
+
new_image = ImageOps.expand(new_image, border=1, fill='white')
|
16 |
+
|
17 |
+
# Get the image size
|
18 |
+
width, height = new_image.size
|
19 |
+
|
20 |
+
# Create a new image to hold the photos
|
21 |
+
output_image = Image.new("RGB", (width * 4, height * 2))
|
22 |
+
|
23 |
+
# Paste the source image into the new image
|
24 |
+
for row in range(2):
|
25 |
+
for col in range(4):
|
26 |
+
output_image.paste(new_image, (col * width, row * height))
|
27 |
+
# Save the output image
|
28 |
+
return output_image
|
29 |
|
30 |
|
31 |
inputs = [
|
32 |
gr.Image(label="Passport Photo", type="pil", image_mode="RGBA"),
|
33 |
gr.ColorPicker(label="Background Color",value="#ff00ff"),
|
34 |
+
gr.Checkbox(label="Select if you want to remove background", value=True)
|
35 |
]
|
36 |
outputs = gr.Image(label="Download Image")
|
37 |
|