remove_bg 1.2.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +17 -6
- data/.gitignore +2 -0
- data/Appraisals +12 -6
- data/CHANGELOG.md +26 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +70 -36
- data/README.md +112 -11
- data/gemfiles/faraday_0_15.gemfile +5 -1
- data/gemfiles/faraday_0_16.gemfile +11 -0
- data/gemfiles/faraday_0_17.gemfile +11 -0
- data/gemfiles/faraday_1_x.gemfile +11 -0
- data/lib/remove_bg.rb +22 -0
- data/lib/remove_bg/account_info.rb +34 -0
- data/lib/remove_bg/api.rb +3 -9
- data/lib/remove_bg/api_client.rb +105 -17
- data/lib/remove_bg/base_request_options.rb +32 -0
- data/lib/remove_bg/composite_result.rb +65 -0
- data/lib/remove_bg/configuration.rb +14 -3
- data/lib/remove_bg/error.rb +19 -1
- data/lib/remove_bg/http_connection.rb +2 -0
- data/lib/remove_bg/image_composer.rb +60 -0
- data/lib/remove_bg/rate_limit_info.rb +34 -0
- data/lib/remove_bg/request_options.rb +25 -15
- data/lib/remove_bg/result.rb +42 -7
- data/lib/remove_bg/result_metadata.rb +14 -0
- data/lib/remove_bg/upload.rb +6 -2
- data/lib/remove_bg/version.rb +1 -1
- data/remove_bg.gemspec +9 -4
- metadata +106 -17
- data/gemfiles/faraday_0_14.gemfile +0 -7
- data/gemfiles/faraday_1rc1.gemfile +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47f8cd273ddfe8639badf0fd59050342af16e542a508162f77fbec7b7a2a5dd4
|
4
|
+
data.tar.gz: 5adcc396f765f7a4858e7c7c4d82d7610b5d42e2200401be29b5ea543f5fdc88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ad4065335850911ee8b45604ed0de465742bdf183078d0ae4e9de52fb1f77519d4d9bd5aa7a042d04e9c0960a8af4f3d0e84cfdb49c6ae48e773626c6ad9639
|
7
|
+
data.tar.gz: a265d257a9e77bd9d87b9ef42c2aff4b0d7b8b7b3482a8717a44b4d3192c5064b0e4e67e62b9d513ecbb67e317c8b470db19194b350ade66d73b602b6ec9a7c8
|
data/.circleci/config.yml
CHANGED
@@ -11,7 +11,16 @@ base_job: &base_job
|
|
11
11
|
|
12
12
|
- run:
|
13
13
|
name: install dependencies
|
14
|
-
command:
|
14
|
+
command: |
|
15
|
+
gem install bundler --version '~> 2.0'
|
16
|
+
bundle config set path vendor/bundle
|
17
|
+
bundle install --jobs=4 --retry=3
|
18
|
+
|
19
|
+
- run:
|
20
|
+
name: install image processsing dependencies
|
21
|
+
command: |
|
22
|
+
sudo apt-get update
|
23
|
+
sudo apt install imagemagick libvips
|
15
24
|
|
16
25
|
- save_cache:
|
17
26
|
paths:
|
@@ -37,10 +46,6 @@ base_job: &base_job
|
|
37
46
|
################################################################################
|
38
47
|
|
39
48
|
jobs:
|
40
|
-
ruby-2.4:
|
41
|
-
<<: *base_job
|
42
|
-
docker:
|
43
|
-
- image: circleci/ruby:2.4
|
44
49
|
ruby-2.5:
|
45
50
|
<<: *base_job
|
46
51
|
docker:
|
@@ -49,6 +54,12 @@ jobs:
|
|
49
54
|
<<: *base_job
|
50
55
|
docker:
|
51
56
|
- image: circleci/ruby:2.6
|
57
|
+
ruby-2.7:
|
58
|
+
<<: *base_job
|
59
|
+
environment:
|
60
|
+
UPLOAD_COVERAGE: 1
|
61
|
+
docker:
|
62
|
+
- image: circleci/ruby:2.7
|
52
63
|
|
53
64
|
################################################################################
|
54
65
|
|
@@ -56,6 +67,6 @@ workflows:
|
|
56
67
|
version: 2
|
57
68
|
multiple-rubies:
|
58
69
|
jobs:
|
59
|
-
- ruby-2.4
|
60
70
|
- ruby-2.5
|
61
71
|
- ruby-2.6
|
72
|
+
- ruby-2.7
|
data/.gitignore
CHANGED
data/Appraisals
CHANGED
@@ -1,11 +1,17 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# Oldest supported Faraday version
|
2
|
+
appraise "faraday-0-15" do
|
3
|
+
gem "faraday", "~> 0.15.0"
|
3
4
|
end
|
4
5
|
|
5
|
-
appraise "faraday-0-
|
6
|
-
gem "faraday", "~> 0.
|
6
|
+
appraise "faraday-0-16" do
|
7
|
+
gem "faraday", "~> 0.16.0"
|
8
|
+
end
|
9
|
+
|
10
|
+
appraise "faraday-0-17" do
|
11
|
+
gem "faraday", "~> 0.17.0"
|
7
12
|
end
|
8
13
|
|
9
|
-
|
10
|
-
|
14
|
+
# Latest in Faraday 1.x series
|
15
|
+
appraise "faraday-1-x" do
|
16
|
+
gem "faraday", "~> 1.0"
|
11
17
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## Unreleased
|
4
|
+
|
5
|
+
## 1.5.0
|
6
|
+
|
7
|
+
- Auto-detect any available image processing libraries
|
8
|
+
- Reduce bandwidth usage by using ZIP format where possible
|
9
|
+
|
10
|
+
## 1.4.1
|
11
|
+
|
12
|
+
- Fixes binary encoding issue - via [#15](https://github.com/remove-bg/ruby/pull/15)
|
13
|
+
|
14
|
+
## 1.4.0
|
15
|
+
|
16
|
+
- Adds support for images up to 25 megapixels ([documentation](https://github.com/remove-bg/ruby#processing-images-over-10-megapixels))
|
17
|
+
- Requires an image processing library to be configured (ImageMagick, GraphicsMagick or libvips)
|
18
|
+
|
19
|
+
## 1.3.0
|
20
|
+
|
21
|
+
- Add `RemoveBg.account_info` which includes available credits - via [#9](https://github.com/remove-bg/ruby/pull/9)
|
22
|
+
- Fix support for Faraday `1.0` - via [#7](https://github.com/remove-bg/ruby/pull/7)
|
23
|
+
- Raise minimum Faraday version to `0.15.0`
|
24
|
+
|
25
|
+
## 1.2.1
|
26
|
+
|
27
|
+
- Add `type` attribute to result object (`X-Type` header from API) - via [#2](https://github.com/remove-bg/ruby/pull/2)
|
28
|
+
|
3
29
|
## 1.2.0
|
4
30
|
|
5
31
|
- Support uppercase file extensions (e.g. `.JPG`)
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,73 +1,107 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/thoughtbot/appraisal.git
|
3
|
+
revision: 586864393e405a67b1457b563a4d5adc99e50e2d
|
4
|
+
ref: 5868643
|
5
|
+
specs:
|
6
|
+
appraisal (2.2.0)
|
7
|
+
bundler
|
8
|
+
rake
|
9
|
+
thor (>= 0.14.0)
|
10
|
+
|
1
11
|
PATH
|
2
12
|
remote: .
|
3
13
|
specs:
|
4
|
-
remove_bg (1.
|
5
|
-
faraday (>= 0.
|
14
|
+
remove_bg (1.5.0)
|
15
|
+
faraday (>= 0.15, < 2)
|
16
|
+
image_processing (>= 1.9, < 2)
|
17
|
+
rubyzip (>= 2.0, < 3)
|
6
18
|
|
7
19
|
GEM
|
8
20
|
remote: https://rubygems.org/
|
9
21
|
specs:
|
10
|
-
addressable (2.
|
11
|
-
public_suffix (>= 2.0.2, <
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
22
|
+
addressable (2.7.0)
|
23
|
+
public_suffix (>= 2.0.2, < 5.0)
|
24
|
+
codecov (0.1.16)
|
25
|
+
json
|
26
|
+
simplecov
|
27
|
+
url
|
16
28
|
coderay (1.1.2)
|
17
29
|
crack (0.4.3)
|
18
30
|
safe_yaml (~> 1.0.0)
|
19
31
|
diff-lcs (1.3)
|
20
|
-
|
21
|
-
|
32
|
+
docile (1.3.2)
|
33
|
+
dotenv (2.7.5)
|
34
|
+
faraday (1.0.1)
|
22
35
|
multipart-post (>= 1.2, < 3)
|
23
|
-
|
24
|
-
|
36
|
+
ffi (1.13.1)
|
37
|
+
hashdiff (1.0.1)
|
38
|
+
image_processing (1.11.0)
|
39
|
+
mini_magick (>= 4.9.5, < 5)
|
40
|
+
ruby-vips (>= 2.0.17, < 3)
|
41
|
+
json (2.3.0)
|
42
|
+
method_source (1.0.0)
|
43
|
+
mini_magick (4.10.1)
|
25
44
|
multipart-post (2.1.1)
|
26
|
-
pry (0.
|
27
|
-
coderay (~> 1.1
|
28
|
-
method_source (~>
|
29
|
-
public_suffix (
|
30
|
-
rake (
|
31
|
-
rspec (3.
|
32
|
-
rspec-core (~> 3.
|
33
|
-
rspec-expectations (~> 3.
|
34
|
-
rspec-mocks (~> 3.
|
35
|
-
rspec-core (3.
|
36
|
-
rspec-support (~> 3.
|
37
|
-
rspec-expectations (3.
|
45
|
+
pry (0.13.1)
|
46
|
+
coderay (~> 1.1)
|
47
|
+
method_source (~> 1.0)
|
48
|
+
public_suffix (4.0.4)
|
49
|
+
rake (13.0.1)
|
50
|
+
rspec (3.9.0)
|
51
|
+
rspec-core (~> 3.9.0)
|
52
|
+
rspec-expectations (~> 3.9.0)
|
53
|
+
rspec-mocks (~> 3.9.0)
|
54
|
+
rspec-core (3.9.2)
|
55
|
+
rspec-support (~> 3.9.3)
|
56
|
+
rspec-expectations (3.9.2)
|
38
57
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
-
rspec-support (~> 3.
|
40
|
-
rspec-mocks (3.
|
58
|
+
rspec-support (~> 3.9.0)
|
59
|
+
rspec-mocks (3.9.1)
|
41
60
|
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
-
rspec-support (~> 3.
|
43
|
-
rspec-support (3.
|
61
|
+
rspec-support (~> 3.9.0)
|
62
|
+
rspec-support (3.9.3)
|
44
63
|
rspec-with_params (0.2.0)
|
45
64
|
rspec (~> 3.0)
|
46
65
|
rspec_junit_formatter (0.4.1)
|
47
66
|
rspec-core (>= 2, < 4, != 2.12.0)
|
67
|
+
ruby-vips (2.0.17)
|
68
|
+
ffi (~> 1.9)
|
69
|
+
rubyzip (2.3.0)
|
48
70
|
safe_yaml (1.0.5)
|
49
|
-
|
50
|
-
|
51
|
-
|
71
|
+
simplecov (0.18.5)
|
72
|
+
docile (~> 1.1)
|
73
|
+
simplecov-html (~> 0.11)
|
74
|
+
simplecov-html (0.12.2)
|
75
|
+
thor (1.0.1)
|
76
|
+
url (0.3.2)
|
77
|
+
vcr (5.1.0)
|
78
|
+
vcr_better_binary (0.1.0)
|
79
|
+
vcr (~> 5.0)
|
80
|
+
webmock (3.8.3)
|
52
81
|
addressable (>= 2.3.6)
|
53
82
|
crack (>= 0.3.2)
|
54
|
-
hashdiff
|
83
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
84
|
+
yard (0.9.25)
|
55
85
|
|
56
86
|
PLATFORMS
|
57
87
|
ruby
|
58
88
|
|
59
89
|
DEPENDENCIES
|
60
|
-
appraisal
|
61
|
-
bundler (~>
|
90
|
+
appraisal!
|
91
|
+
bundler (~> 2.0)
|
92
|
+
codecov
|
62
93
|
dotenv
|
63
94
|
pry
|
64
|
-
rake
|
95
|
+
rake
|
65
96
|
remove_bg!
|
66
97
|
rspec (~> 3.8)
|
67
98
|
rspec-with_params
|
68
99
|
rspec_junit_formatter
|
100
|
+
simplecov
|
69
101
|
vcr
|
102
|
+
vcr_better_binary
|
70
103
|
webmock
|
104
|
+
yard
|
71
105
|
|
72
106
|
BUNDLED WITH
|
73
|
-
1.
|
107
|
+
2.1.4
|
data/README.md
CHANGED
@@ -2,16 +2,58 @@
|
|
2
2
|
|
3
3
|
# Ruby library
|
4
4
|
|
5
|
-
[](https://circleci.com/gh/remove-bg/ruby/tree/master) [](https://rubygems.org/gems/remove_bg)
|
5
|
+
[](https://circleci.com/gh/remove-bg/ruby/tree/master) [](https://rubygems.org/gems/remove_bg) [](https://codecov.io/gh/remove-bg/ruby)
|
6
6
|
|
7
|
-
##
|
7
|
+
## Quickstart installation
|
8
8
|
|
9
|
-
|
10
|
-
- Or install it yourself as: `gem install remove_bg`
|
9
|
+
Add the gem to your `Gemfile` and run `bundle install`:
|
11
10
|
|
12
|
-
|
11
|
+
```
|
12
|
+
gem "remove_bg"
|
13
|
+
```
|
14
|
+
|
15
|
+
Or run `gem install remove_bg` to install globally.
|
16
|
+
|
17
|
+
Please note the base configuration has the following resolution limits:
|
18
|
+
|
19
|
+
| Output format | Resolution limit |
|
20
|
+
|---------------|------------------|
|
21
|
+
| PNG | 10 megapixels |
|
22
|
+
| JPG | 25 megapixels |
|
23
|
+
|
24
|
+
## Full installation
|
13
25
|
|
14
|
-
|
26
|
+
For best performance and quality the gem requires an image processing library.
|
27
|
+
Please install one of the following libraries:
|
28
|
+
|
29
|
+
- [ImageMagick](https://www.imagemagick.org/)
|
30
|
+
- [GraphicsMagick](http://www.graphicsmagick.org/)
|
31
|
+
- [libvips](http://libvips.github.io/libvips/)
|
32
|
+
|
33
|
+
The gem will auto-detect any image processing libraries present. However you may
|
34
|
+
prefer to explicitly configure which library to use:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
RemoveBg.configure do |config|
|
38
|
+
config.image_processor = :minimagick # For ImageMagick or GraphicsMagick
|
39
|
+
# or
|
40
|
+
config.image_processor = :vips
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
The full installation has the following resolution limits:
|
45
|
+
|
46
|
+
| Output format | Resolution limit |
|
47
|
+
|---------------|------------------|
|
48
|
+
| PNG | 25 megapixels |
|
49
|
+
| JPG | 25 megapixels |
|
50
|
+
| ZIP | 25 megapixels |
|
51
|
+
|
52
|
+
# Usage
|
53
|
+
|
54
|
+
For more in-depth documentation please see [RubyDoc](https://www.rubydoc.info/gems/remove_bg)
|
55
|
+
|
56
|
+
## Configuring an API key
|
15
57
|
|
16
58
|
To configure a global API key (used by default unless overridden per request):
|
17
59
|
|
@@ -25,7 +67,7 @@ It's not recommended to commit your API key to version control. You may want to
|
|
25
67
|
read the API key from an environment variable (e.g.
|
26
68
|
`ENV.fetch("REMOVE_BG_API_KEY")`) or find an alternative method.
|
27
69
|
|
28
|
-
|
70
|
+
## Removing the background from an image
|
29
71
|
|
30
72
|
Currently the gem supports removing the background from a file or a URL:
|
31
73
|
|
@@ -34,7 +76,7 @@ RemoveBg.from_file("image.png")
|
|
34
76
|
RemoveBg.from_url("http://example.com/image.png")
|
35
77
|
```
|
36
78
|
|
37
|
-
|
79
|
+
## Request options
|
38
80
|
|
39
81
|
The processing options outlined in the [API reference](https://www.remove.bg/api)
|
40
82
|
can be specified per request:
|
@@ -49,7 +91,7 @@ The API key can also be specified per request:
|
|
49
91
|
RemoveBg.from_file("image.png", api_key: "<api-key>")
|
50
92
|
```
|
51
93
|
|
52
|
-
|
94
|
+
## Handling the result
|
53
95
|
|
54
96
|
Background removal requests return a result object which includes the processed
|
55
97
|
image data and the metadata about the operation.
|
@@ -69,6 +111,54 @@ result.save("processed/image.png")
|
|
69
111
|
result.save("image.png", overwrite: true) # Careful!
|
70
112
|
```
|
71
113
|
|
114
|
+
## Producing transparent images over 10 megapixels
|
115
|
+
|
116
|
+
After configuring a full installation (detailed above) you can process images
|
117
|
+
over 10 megapixels with a transparent output.
|
118
|
+
|
119
|
+
Process images with either the `png` or `zip` format. If you specify the `zip`
|
120
|
+
format it's possible to save the archive and handle composition yourself.
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
result = RemoveBg.from_file("large-image.jpg", format: "zip")
|
124
|
+
|
125
|
+
result.save("result-with-transparency.png")
|
126
|
+
# or
|
127
|
+
result.save_zip("result.zip") # If you want to handle composition yourself
|
128
|
+
```
|
129
|
+
|
130
|
+
## Rate limits
|
131
|
+
|
132
|
+
The [API has rate limits][rate-limits]. Image processing results include the
|
133
|
+
rate limit information:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
result = RemoveBg.from_file("image.jpg")
|
137
|
+
result.rate_limit.to_s
|
138
|
+
# => <RateLimit reset_at='2020-05-20T12:00:00Z' total=500 remaining=499 retry_after_seconds=nil>
|
139
|
+
```
|
140
|
+
|
141
|
+
If you exceed the rate limit a `RemoveBg::RateLimitError` exception will be
|
142
|
+
raised. This also contains further information via the `#rate_limit` method.
|
143
|
+
|
144
|
+
[rate-limits]: https://www.remove.bg/api#rate-limit
|
145
|
+
|
146
|
+
## Fetching account information
|
147
|
+
|
148
|
+
To display the [account information][account-info] for the currently configured
|
149
|
+
API key:
|
150
|
+
|
151
|
+
[account-info]: https://www.remove.bg/api#operations-tag-Fetch_account_info
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
account = RemoveBg.account_info # If an API key is set via RemoveBg.configuration
|
155
|
+
# or
|
156
|
+
account = RemoveBg.account_info(api_key: "<api_key>")
|
157
|
+
|
158
|
+
account.api.free_calls # => 50
|
159
|
+
account.credits.total # => 200
|
160
|
+
```
|
161
|
+
|
72
162
|
## Examples
|
73
163
|
|
74
164
|
- [Bulk processing][bulk-processing] a directory of JPG and PNG files
|
@@ -85,11 +175,22 @@ Bug reports and pull requests are welcome on GitHub at [remove-bg/ruby](https://
|
|
85
175
|
|
86
176
|
## Development
|
87
177
|
|
178
|
+
### Setup
|
179
|
+
|
88
180
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
89
181
|
`rake spec` to run the tests.
|
90
182
|
|
91
|
-
|
92
|
-
release a new version, update the version number in `version.rb`, and then run
|
183
|
+
### Releasing a new version
|
184
|
+
To release a new version, update the version number in `version.rb`, and then run
|
93
185
|
`bundle exec rake release`, which will create a git tag for the version, push
|
94
186
|
git commits and tags, and push the `.gem` file to
|
95
187
|
[rubygems.org](https://rubygems.org).
|
188
|
+
|
189
|
+
### Documentation
|
190
|
+
|
191
|
+
To preview the [YARD documentation](https://yardoc.org/) locally run:
|
192
|
+
|
193
|
+
```
|
194
|
+
bundle exec yard server --reload
|
195
|
+
open http://localhost:8808/
|
196
|
+
```
|