项目作者: remove-bg

项目描述 :
Go-based command-line tool for the remove.bg API
高级语言: Go
项目地址: git://github.com/remove-bg/go.git
创建时间: 2019-04-10T15:39:45Z
项目社区:https://github.com/remove-bg/go

开源协议:

下载


remove.bg CLI 2.0

⚠️ This repository is archived! Please read the message below.

We released a new version of the remove.bg CLI. You can download it here: https://github.com/remove-bg/remove-bg-cli
The go version of our CLI is no longer maintained nor supported.


remove.bg CLI

Installation

Download

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

Homebrew

  1. brew install remove-bg/homebrew-tap/removebg

deb / rpm

Download the .deb or .rpm from the releases page and install with
dpkg -i and rpm -i.

For the latest deb package supporting x86-64 you can also run:

  1. curl -LO $(curl https://api.github.com/repos/remove-bg/go/releases/latest | grep -o "https://github.com/remove-bg/go/releases/download/.*linux_amd64.deb")
  2. sudo dpkg -i removebg*.deb

Usage

  1. 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):

  1. export REMOVE_BG_API_KEY=xyz

Alternatively you can specify the API key per command:

  1. 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:

  1. removebg images/*.{png,jpg}

Given the following input:

  1. images/
  2. ├── dog.jpg
  3. └── cat.png

The result would be:

  1. images/
  2. ├── dog.jpg
  3. ├── cat.png
  4. ├── dog-removebg.png
  5. └── 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:

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

Given the following input:

  1. originals/
  2. ├── dog.jpg
  3. └── cat.png

The result would be:

  1. originals/
  2. ├── dog.jpg
  3. └── cat.png
  4. processed/
  5. ├── dog.png
  6. └── 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.

Image processing options

Please see the API documentation for further details.

  • --size (default auto)
  • --type
  • --channels
  • --bg-color
  • --format (default: png)
  • --extra-api-options for forwarding any unlisted/new options to the API
    • Formatted as a URI encoded string (= between key/value, delimited with &)
    • e.g. --extra-api-options 'crop=true&add_shadow=true'

Examples

  1. # Producing a JPG with a grey background at the path: processed/subject.jpg
  2. removebg subject.jpg --format jpg --bg-color 7a7a7a --output-directory processed
  3. # Producing a large transparent PNG image up to 25 megapixels
  4. removebg large.jpg --size full --format png
  5. # Processing a car image with additional API options
  6. removebg car.jpg --type car --extra-api-options 'add_shadow=true&semitransparency=true'

Development

Prerequisites:

Getting started:

  1. git clone git@github.com:remove-bg/go.git $GOPATH/github.com/remove-bg/go
  2. cd $GOPATH/github.com/remove-bg/go
  3. bin/setup
  4. bin/test

To build & try out locally:

  1. go build -o removebg main.go
  2. ./removebg --help

Releasing a new version

  1. GITHUB_TOKEN=xyz bin/release vX.Y.Z