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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc4012fc81007849a4d6cbfb9dd839d079991b34e441a987564b69d84887c1c1
4
- data.tar.gz: 990aad3bda51bae6df1899df3064f874993e59f3b47e44f9b34f3fd7f875036c
3
+ metadata.gz: 47f8cd273ddfe8639badf0fd59050342af16e542a508162f77fbec7b7a2a5dd4
4
+ data.tar.gz: 5adcc396f765f7a4858e7c7c4d82d7610b5d42e2200401be29b5ea543f5fdc88
5
5
  SHA512:
6
- metadata.gz: 1ae8f6ae4b188346c490887d47c541a155c0bafc650ca90fda42a250db4f05485a061ca63ca4c48ddf4ed09c3ae664cfde1cb49b1a3c5aa7916c35d04fb391f4
7
- data.tar.gz: cd9ad405b78632a09053a33cdc2a1b3431f068758299329a64fe236c6d5e53e7790aea453b32a3b3e9bc8d97cc2ce9efe1f3e766c4ca025416a2d7ef6e6a8623
6
+ metadata.gz: 4ad4065335850911ee8b45604ed0de465742bdf183078d0ae4e9de52fb1f77519d4d9bd5aa7a042d04e9c0960a8af4f3d0e84cfdb49c6ae48e773626c6ad9639
7
+ data.tar.gz: a265d257a9e77bd9d87b9ef42c2aff4b0d7b8b7b3482a8717a44b4d3192c5064b0e4e67e62b9d513ecbb67e317c8b470db19194b350ade66d73b602b6ec9a7c8
@@ -11,7 +11,16 @@ base_job: &base_job
11
11
 
12
12
  - run:
13
13
  name: install dependencies
14
- command: bundle install --jobs=4 --retry=3 --path vendor/bundle
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
@@ -18,3 +18,5 @@ test-results
18
18
  gemfiles/*.gemfile.lock
19
19
 
20
20
  examples/output
21
+
22
+ .ruby-version
data/Appraisals CHANGED
@@ -1,11 +1,17 @@
1
- appraise "faraday-0-14" do
2
- gem "faraday", "~> 0.14"
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-15" do
6
- gem "faraday", "~> 0.15"
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
- appraise "faraday-1rc1" do
10
- gem "faraday", "1.0.0.pre.rc1"
14
+ # Latest in Faraday 1.x series
15
+ appraise "faraday-1-x" do
16
+ gem "faraday", "~> 1.0"
11
17
  end
@@ -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
@@ -1,3 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ group :development do
6
+ gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git", ref: "5868643"
7
+ end
@@ -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.2.0)
5
- faraday (>= 0.14, < 2)
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.6.0)
11
- public_suffix (>= 2.0.2, < 4.0)
12
- appraisal (2.2.0)
13
- bundler
14
- rake
15
- thor (>= 0.14.0)
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
- dotenv (2.7.1)
21
- faraday (0.15.4)
32
+ docile (1.3.2)
33
+ dotenv (2.7.5)
34
+ faraday (1.0.1)
22
35
  multipart-post (>= 1.2, < 3)
23
- hashdiff (0.3.8)
24
- method_source (0.9.2)
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.12.2)
27
- coderay (~> 1.1.0)
28
- method_source (~> 0.9.0)
29
- public_suffix (3.0.3)
30
- rake (12.3.2)
31
- rspec (3.8.0)
32
- rspec-core (~> 3.8.0)
33
- rspec-expectations (~> 3.8.0)
34
- rspec-mocks (~> 3.8.0)
35
- rspec-core (3.8.0)
36
- rspec-support (~> 3.8.0)
37
- rspec-expectations (3.8.2)
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.8.0)
40
- rspec-mocks (3.8.0)
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.8.0)
43
- rspec-support (3.8.0)
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
- thor (0.20.3)
50
- vcr (4.0.0)
51
- webmock (3.5.1)
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 (~> 1.17)
90
+ appraisal!
91
+ bundler (~> 2.0)
92
+ codecov
62
93
  dotenv
63
94
  pry
64
- rake (~> 12.0)
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.17.3
107
+ 2.1.4
data/README.md CHANGED
@@ -2,16 +2,58 @@
2
2
 
3
3
  # Ruby library
4
4
 
5
- [![CircleCI](https://circleci.com/gh/remove-bg/ruby/tree/master.svg?style=shield)](https://circleci.com/gh/remove-bg/ruby/tree/master) [![Gem Version](https://badge.fury.io/rb/remove_bg.svg)](https://rubygems.org/gems/remove_bg)
5
+ [![CircleCI](https://circleci.com/gh/remove-bg/ruby/tree/master.svg?style=shield)](https://circleci.com/gh/remove-bg/ruby/tree/master) [![Gem Version](https://badge.fury.io/rb/remove_bg.svg)](https://rubygems.org/gems/remove_bg) [![codecov](https://codecov.io/gh/remove-bg/ruby/branch/master/graph/badge.svg)](https://codecov.io/gh/remove-bg/ruby)
6
6
 
7
- ## Installation
7
+ ## Quickstart installation
8
8
 
9
- - Add `gem "remove_bg"` to your application's Gemfile and then execute `bundle`.
10
- - Or install it yourself as: `gem install remove_bg`
9
+ Add the gem to your `Gemfile` and run `bundle install`:
11
10
 
12
- ## Usage
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
- ### Configuring an API key
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
- ### Removing the background from an image
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
- #### Request options
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
- #### Handling the result
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
- To install this gem onto your local machine, run `bundle exec rake install`. To
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
+ ```
@@ -2,6 +2,10 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "faraday", "~> 0.15"
5
+ gem "faraday", "~> 0.15.0"
6
+
7
+ group :development do
8
+ gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git", ref: "5868643"
9
+ end
6
10
 
7
11
  gemspec path: "../"