mehulkatara commited on
Commit
208c40c
·
1 Parent(s): da190f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -20
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 = 'Background Color'):
7
- image = remove(passport)
8
- new_image = Image.new("RGB", image.size, color)
9
- new_image.paste(image, mask=image)
10
- # Add a black border of 10 pixels on all sides
11
- new_image = ImageOps.expand(new_image, border=5, fill='black')
12
- new_image = ImageOps.expand(new_image, border=1, fill='white')
13
-
14
- # Get the image size
15
- width, height = new_image.size
16
-
17
- # Create a new image to hold the photos
18
- output_image = Image.new("RGB", (width * 4, height * 2))
19
-
20
- # Paste the source image into the new image
21
- for row in range(2):
22
- for col in range(4):
23
- output_image.paste(new_image, (col * width, row * height))
24
- # Save the output image
25
- return output_image
 
 
 
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