Skip to content

GDKAMRUL1/Remove-Image-Background

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Remove-Image-Background

Directory Structure: bash Copy code Remove-Image-Background/ ├── main.py # Main script for removing backgrounds ├── requirements.txt # Python dependencies ├── README.md # Project documentation └── example.jpg # Example image

  1. Python Script (main.py) Save the following script in a file named main.py:

python Copy code from rembg import remove from PIL import Image import io import os

def remove_background(input_path, output_path): """ Removes the background from an image and saves the result.

:param input_path: Path to the input image.
:param output_path: Path to save the output image.
"""
try:
    with open(input_path, 'rb') as file:
        input_image = file.read()
        output_image = remove(input_image)

    # Save the output
    output = Image.open(io.BytesIO(output_image))
    output.save(output_path, format='PNG')
    print(f"Background removed and saved to: {output_path}")
except Exception as e:
    print(f"Error occurred: {e}")

if name == "main": input_image = input("Enter the input image path: ").strip() output_image = input("Enter the output image path (e.g., output.png): ").strip()

if not os.path.exists(input_image):
    print(f"Error: The file '{input_image}' does not exist.")
else:
    remove_background(input_image, output_image)
  1. Requirements File (requirements.txt) Specify the dependencies for your project:

Copy code rembg Pillow 3. README File (README.md) Write the documentation for your GitHub repository:

markdown Copy code

Remove-Image-Background

A simple Python tool to remove image backgrounds using rembg.

Features

  • Remove the background from any image.
  • Save the output as a transparent PNG file.

Installation

  1. Clone the repository:
    git clone https://github.com/gdkamrul1/Remove-Image-Background.git
    cd Remove-Image-Background

Install dependencies: bash Copy code pip install -r requirements.txt Usage Run the script:

bash Copy code python main.py Provide the path to your input image and specify the output image file name. The processed image will be saved with a transparent background.

Example Input:

Output:

Website Visit my website for more projects: kamrulmollah.com

License This project is licensed under the MIT License.

csharp Copy code

4. Push to GitHub

  1. Initialize Git and commit the files:
    git init
    git add .
    git commit -m "Initial commit: Remove-Image-Background tool"

Create a new GitHub repository at GitHub. Link the local repository to GitHub: bash Copy code git remote add origin https://github.com/gdkamrul1/Remove-Image-Background.git git branch -M main git push -u origin main 5. Visit Your Website Add a link to your GitHub repository from https://kamrulmollah.com for better visibility. Update the README.md file or project description as needed.

Let me know if you need additional help with deployment or setup!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages