Skip to content
Official ruby gem for the remove.bg API
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Test compatibility with multiple Faraday versions Apr 1, 2019
bin Initial gem skeleton and RSpec setup Mar 10, 2019
examples Add bulk process example Apr 3, 2019
gemfiles
lib
resources
spec
.env.test
.gitignore Add bulk process example Apr 3, 2019
.rspec
Appraisals Test compatibility with multiple Faraday versions Apr 1, 2019
CHANGELOG.md
Gemfile Initial gem skeleton and RSpec setup Mar 10, 2019
Gemfile.lock
LICENSE
README.md Add RubyGems version badge to README Apr 3, 2019
Rakefile Initial gem skeleton and RSpec setup Mar 10, 2019
remove_bg.gemspec Add bulk process example Apr 3, 2019

README.md

RemoveBG

Ruby library

CircleCI Gem Version

Installation

  • Add gem "remove_bg" to your application's Gemfile and then execute bundle.
  • Or install it yourself as: gem install remove_bg

Usage

Configuring an API key

To configure a global API key (used by default unless overridden per request):

RemoveBg.configure do |config|
  config.api_key = "<api-key>"
end

It's not recommended to commit your API key to version control. You may want to read the API key from an environment variable (e.g. ENV.fetch("REMOVE_BG_API_KEY")) or find an alternative method.

Removing the background from an image

Currently the gem supports removing the background from a file or a URL:

RemoveBg.from_file("image.png")
RemoveBg.from_url("http://example.com/image.png")

Request options

The processing options outlined in the API reference can be specified per request:

RemoveBg.from_file("image.png", size: "hd", type: "product", channels: "rgba")

The API key can also be specified per request:

RemoveBg.from_file("image.png", api_key: "<api-key>")

Handling the result

Background removal requests return a result object which includes the processed image data and the metadata about the operation.

result = RemoveBg.from_file("image.png")
result.data             # => "\x89PNG..."
result.height           # => 333
result.width            # => 500
result.credits_charged  # => 1

There's also a #save convenience method:

result.save("processed/image.png")
result.save("image.png", overwrite: true) # Careful!

Examples

License

The gem is available as open source under the terms of the MIT License.

Contributing

Bug reports and pull requests are welcome on GitHub at remove-bg/ruby.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

You can’t perform that action at this time.