Skip to content

Commit 7f0e86b

Browse files
committed
Final: Updated project information
1 parent b17113e commit 7f0e86b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

assets/removed_bg.png

170 KB
Loading

src/python/background_remover.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from rembg import remove
2+
from PIL import Image
3+
4+
5+
def remove_bg(input_path, output_path):
6+
"""Removes the background from an image and saves the result."""
7+
8+
try:
9+
input_img = Image.open(input_path)
10+
output_img = remove(input_img)
11+
output_img.save(output_path)
12+
print(f"Background removed successfully! Saved to {output_path}")
13+
except FileNotFoundError:
14+
print(f"Error: File not found at {input_path}")
15+
except Exception as e:
16+
print(f"An error occurred: {e}")
17+
18+
19+
def main():
20+
input_path = input("Enter the path to your image: ")
21+
output_choice = input("Do you want to specify the output path? (y/n): ")
22+
23+
if output_choice.lower() == 'y':
24+
output_path = input("Enter the desired output path: ")
25+
else:
26+
output_path = "removed_bg.png" # Default output name
27+
28+
remove_bg(input_path, output_path)
29+
30+
31+
if __name__ == "__main__":
32+
main()

0 commit comments

Comments
 (0)