Spaces:
Running
Running
from rembg import remove | |
from PIL import Image, ImageOps | |
import gradio as gr | |
def image_mod(image): | |
output = remove(image) | |
image = output.convert("RGBA") | |
new_image = Image.new("RGBA", image.size, "MAGENTA") | |
new_image.paste(image, mask=image) | |
# Add a black border of 10 pixels on all sides | |
new_image = ImageOps.expand(new_image, border=5, fill='black') | |
# Get the image size | |
width, height = new_image.size | |
# Calculate the number of photos per row | |
num_per_row = int(width / 4) | |
# Create a new image to hold the photos | |
output_image = Image.new("RGB", (width * 4, height * 2)) | |
# Paste the source image into the new image | |
for row in range(2): | |
for col in range(4): | |
output_image.paste(new_image, (col * width, row * height)) | |
# Save the output image | |
return output_image | |
demo = gr.Interface( | |
image_mod, | |
gr.Image(type="pil"), | |
"image", | |
) | |
if __name__ == "__main__": | |
demo.launch() | |