• Stars
    star
    164
  • Rank 223,333 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 2 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

remove.bg CLI

CircleCI

Installation

Download

You can download latest stable release (Windows, Mac, and Linux supported)

Homebrew

brew install remove-bg/homebrew-tap/removebg

Installation

Download the .zip or .tar.gz from the releases page and unzip with your favorite decompression tool. Then move the binary to a folder in your path.

Usage

removebg [options] <file>...

API key

To process images you'll need your remove.bg API key.

To use the API key for all requests you can export the following environment variable in your shell profile (e.g. ~/.bashrc / ~/.zshrc):

export REMOVE_BG_API_KEY=xyz

Alternatively you can specify the API key per command:

removebg --api-key xyz images/image1.jpg

Processing a directory of images

Saving to the same directory (default)

If you want to remove the background from all the PNG and JPG images in a directory, and save the transparent images in the same directory:

removebg images/*.{png,jpg}

Given the following input:

images/
β”œβ”€β”€ dog.jpg
└── cat.png

The result would be:

images/
β”œβ”€β”€ dog.jpg
β”œβ”€β”€ cat.png
β”œβ”€β”€ dog-removebg.png
└── cat-removebg.png

Saving to a different directory (--output-directory)

If you want to remove the background from all the PNG and JPG images in a directory, and save the transparent images in a different directory:

mkdir processed
removebg --output-directory processed originals/*.{png,jpg}

Given the following input:

originals/
β”œβ”€β”€ dog.jpg
└── cat.png

The result would be:

originals/
β”œβ”€β”€ dog.jpg
└── cat.png

processed/
β”œβ”€β”€ dog.png
└── cat.png

CLI options

  • --api-key or REMOVE_BG_API_KEY environment variable (required).

  • --output-directory (optional) - The output directory for processed images.

  • --reprocess-existing - Images which have already been processed are skipped by default to save credits. Specify this flag to force reprocessing.

  • --confirm-batch-over (default 50) - Prompt for confirmation before processing batches over this size. Specify -1 to disable this safeguard.

  • --skip-png-format-optimization - By default the cli calls the API with zip format for maximum output resolution. When specifying this flag it will use png format to save bandwidth by limiting the output resolution to 10 megapixels.

Image processing options

Please see the API documentation for further details.

  • --size (default auto)
  • --type
  • --channels
  • --bg-color
  • --bg-image-file
  • --format (default: png)
  • --extra-api-option for forwarding any unlisted/new option to the API
    • Formatted as key/value pair (= between key/value)
    • it is possible to use this option multiple times e.g. --extra-api-option crop=true --extra-api-option add_shadow=true

Examples

# Producing a JPG with a grey background at the path: processed/subject.jpg
removebg subject.jpg --format jpg --bg-color 7a7a7a --output-directory processed

# Producing a large transparent PNG image up to 25 megapixels
removebg large.jpg --size full --format png

# Processing a car image with additional API options
removebg car.jpg --type car --extra-api-option add_shadow=true --extra-api-option semitransparency=true

zip2png

The zip2png command is now included in the remove.bg command line interface. Pass the result zip file from remove.bg as parameter and the command converts it into a transparent png file.

removebg zip2png --file /path/to/file.zip 

Development

Prerequisites:

  • nodejs 14.18.1

Getting started:

git clone [email protected]:remove-bg/remove-bg-cli.git
cd remove-bg-cli
npm i
npm run build
npm run test

To build & try out locally:

npm run build
./dist/removebg --help

Creating a binary executable

  • npm i -g pkg
  • npm run build