app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
from rembg import remove from PIL import Image import io def remove_bg(input_path, output_path): # Read the image as bytes with open(input_path, 'rb') as f: input_bytes = f.read() # Remove the background output_bytes = remove(input_bytes) # Convert bytes to image and save as PNG (transparent background) output_image = Image.open(io.BytesIO(output_bytes)) output_image.save(output_path) # Example usage remove_bg("profile.jpg", "output.png") |