remove_bg 1.5.0 → 2.0.1
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 +329 -59
- data/.depfu.yml +21 -0
- data/.editorconfig +19 -0
- data/.gitignore +8 -8
- data/.grenrc.json +20 -0
- data/.rspec +5 -0
- data/.rubocop.yml +43 -0
- data/.tool-versions +1 -0
- data/Appraisals +49 -10
- data/CHANGELOG.md +19 -2
- data/Gemfile +2 -5
- data/Gemfile.lock +132 -78
- data/LICENSE.md +25 -0
- data/README.md +31 -12
- data/Rakefile +4 -0
- data/SECURITY.md +36 -0
- data/gemfiles/faraday_2_0.gemfile +7 -0
- data/gemfiles/faraday_2_1.gemfile +7 -0
- data/gemfiles/faraday_2_2.gemfile +7 -0
- data/gemfiles/faraday_2_3.gemfile +7 -0
- data/gemfiles/faraday_2_4.gemfile +7 -0
- data/gemfiles/faraday_2_5.gemfile +7 -0
- data/gemfiles/faraday_2_6.gemfile +7 -0
- data/gemfiles/faraday_2_7.gemfile +7 -0
- data/gemfiles/faraday_2_8.gemfile +7 -0
- data/gemfiles/faraday_2_9.gemfile +7 -0
- data/gemfiles/faraday_2_x.gemfile +7 -0
- data/lib/remove_bg/account_info.rb +2 -0
- data/lib/remove_bg/api.rb +2 -0
- data/lib/remove_bg/api_client.rb +12 -12
- data/lib/remove_bg/base_request_options.rb +2 -0
- data/lib/remove_bg/composite_result.rb +19 -10
- data/lib/remove_bg/configuration.rb +2 -0
- data/lib/remove_bg/error.rb +3 -1
- data/lib/remove_bg/http_connection.rb +7 -4
- data/lib/remove_bg/image_composer.rb +13 -12
- data/lib/remove_bg/rate_limit_info.rb +9 -6
- data/lib/remove_bg/request_options.rb +3 -3
- data/lib/remove_bg/result.rb +13 -3
- data/lib/remove_bg/result_metadata.rb +2 -0
- data/lib/remove_bg/upload.rb +5 -8
- data/lib/remove_bg/url_validator.rb +4 -4
- data/lib/remove_bg/version.rb +3 -1
- data/lib/remove_bg.rb +2 -0
- data/remove_bg.gemspec +43 -20
- data/resources/removebgByCanva.svg +47 -0
- data/sonar-project.properties +22 -0
- data/tasks/version.rake +34 -0
- metadata +207 -82
- data/.env.test +0 -2
- data/LICENSE +0 -21
- data/gemfiles/faraday_0_15.gemfile +0 -11
- data/gemfiles/faraday_0_16.gemfile +0 -11
- data/gemfiles/faraday_0_17.gemfile +0 -11
- data/gemfiles/faraday_1_x.gemfile +0 -11
data/Gemfile.lock
CHANGED
@@ -1,107 +1,161 @@
|
|
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
|
-
|
11
1
|
PATH
|
12
2
|
remote: .
|
13
3
|
specs:
|
14
|
-
remove_bg (
|
15
|
-
faraday (>=
|
16
|
-
|
4
|
+
remove_bg (2.0.1)
|
5
|
+
faraday (>= 2, <= 3)
|
6
|
+
faraday-multipart (~> 1.0)
|
7
|
+
faraday-retry (~> 2.2)
|
8
|
+
image_processing (~> 1.12)
|
17
9
|
rubyzip (>= 2.0, < 3)
|
18
10
|
|
19
11
|
GEM
|
20
12
|
remote: https://rubygems.org/
|
21
13
|
specs:
|
22
|
-
addressable (2.7
|
23
|
-
public_suffix (>= 2.0.2, <
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
14
|
+
addressable (2.8.7)
|
15
|
+
public_suffix (>= 2.0.2, < 7.0)
|
16
|
+
appraisal (2.5.0)
|
17
|
+
bundler
|
18
|
+
rake
|
19
|
+
thor (>= 0.14.0)
|
20
|
+
ast (2.4.2)
|
21
|
+
bigdecimal (3.1.8)
|
22
|
+
coderay (1.1.3)
|
23
|
+
crack (1.0.0)
|
24
|
+
bigdecimal
|
25
|
+
rexml
|
26
|
+
diff-lcs (1.5.1)
|
27
|
+
docile (1.4.0)
|
28
|
+
faraday (2.10.0)
|
29
|
+
faraday-net_http (>= 2.0, < 3.2)
|
30
|
+
logger
|
31
|
+
faraday-multipart (1.0.4)
|
32
|
+
multipart-post (~> 2)
|
33
|
+
faraday-net_http (3.1.0)
|
34
|
+
net-http
|
35
|
+
faraday-retry (2.2.1)
|
36
|
+
faraday (~> 2.0)
|
37
|
+
ffi (1.17.0)
|
38
|
+
ffi (1.17.0-arm64-darwin)
|
39
|
+
ffi (1.17.0-x86_64-linux-gnu)
|
40
|
+
hashdiff (1.1.0)
|
41
|
+
htmlentities (4.3.4)
|
42
|
+
image_processing (1.12.2)
|
39
43
|
mini_magick (>= 4.9.5, < 5)
|
40
44
|
ruby-vips (>= 2.0.17, < 3)
|
41
|
-
json (2.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
45
|
+
json (2.7.2)
|
46
|
+
language_server-protocol (3.17.0.3)
|
47
|
+
logger (1.6.0)
|
48
|
+
method_source (1.1.0)
|
49
|
+
mini_magick (4.13.2)
|
50
|
+
multipart-post (2.4.1)
|
51
|
+
net-http (0.4.1)
|
52
|
+
uri
|
53
|
+
parallel (1.25.1)
|
54
|
+
parser (3.3.4.0)
|
55
|
+
ast (~> 2.4.1)
|
56
|
+
racc
|
57
|
+
pry (0.14.2)
|
46
58
|
coderay (~> 1.1)
|
47
59
|
method_source (~> 1.0)
|
48
|
-
public_suffix (
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
60
|
+
public_suffix (6.0.0)
|
61
|
+
racc (1.8.0)
|
62
|
+
rainbow (3.1.1)
|
63
|
+
rake (13.2.1)
|
64
|
+
regexp_parser (2.9.2)
|
65
|
+
rexml (3.3.2)
|
66
|
+
strscan
|
67
|
+
rspec (3.13.0)
|
68
|
+
rspec-core (~> 3.13.0)
|
69
|
+
rspec-expectations (~> 3.13.0)
|
70
|
+
rspec-mocks (~> 3.13.0)
|
71
|
+
rspec-core (3.13.0)
|
72
|
+
rspec-support (~> 3.13.0)
|
73
|
+
rspec-expectations (3.13.1)
|
57
74
|
diff-lcs (>= 1.2.0, < 2.0)
|
58
|
-
rspec-support (~> 3.
|
59
|
-
rspec-mocks (3.
|
75
|
+
rspec-support (~> 3.13.0)
|
76
|
+
rspec-mocks (3.13.1)
|
60
77
|
diff-lcs (>= 1.2.0, < 2.0)
|
61
|
-
rspec-support (~> 3.
|
62
|
-
rspec-
|
63
|
-
|
78
|
+
rspec-support (~> 3.13.0)
|
79
|
+
rspec-sonarqube-formatter (1.5.0)
|
80
|
+
htmlentities (~> 4.3.3)
|
81
|
+
rspec (~> 3.0)
|
82
|
+
rspec-support (3.13.1)
|
83
|
+
rspec-with_params (0.3.0)
|
64
84
|
rspec (~> 3.0)
|
65
|
-
rspec_junit_formatter (0.
|
85
|
+
rspec_junit_formatter (0.6.0)
|
66
86
|
rspec-core (>= 2, < 4, != 2.12.0)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
87
|
+
rubocop (1.65.0)
|
88
|
+
json (~> 2.3)
|
89
|
+
language_server-protocol (>= 3.17.0)
|
90
|
+
parallel (~> 1.10)
|
91
|
+
parser (>= 3.3.0.2)
|
92
|
+
rainbow (>= 2.2.2, < 4.0)
|
93
|
+
regexp_parser (>= 2.4, < 3.0)
|
94
|
+
rexml (>= 3.2.5, < 4.0)
|
95
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
96
|
+
ruby-progressbar (~> 1.7)
|
97
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
98
|
+
rubocop-ast (1.31.3)
|
99
|
+
parser (>= 3.3.1.0)
|
100
|
+
rubocop-performance (1.21.1)
|
101
|
+
rubocop (>= 1.48.1, < 2.0)
|
102
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
103
|
+
rubocop-rake (0.6.0)
|
104
|
+
rubocop (~> 1.0)
|
105
|
+
rubocop-rspec (3.0.3)
|
106
|
+
rubocop (~> 1.61)
|
107
|
+
ruby-progressbar (1.13.0)
|
108
|
+
ruby-vips (2.2.1)
|
109
|
+
ffi (~> 1.12)
|
110
|
+
rubyzip (2.3.2)
|
111
|
+
simplecov (0.22.0)
|
72
112
|
docile (~> 1.1)
|
73
113
|
simplecov-html (~> 0.11)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
114
|
+
simplecov_json_formatter (~> 0.1)
|
115
|
+
simplecov-cobertura (2.1.0)
|
116
|
+
rexml
|
117
|
+
simplecov (~> 0.19)
|
118
|
+
simplecov-html (0.12.3)
|
119
|
+
simplecov_json_formatter (0.1.4)
|
120
|
+
strscan (3.1.0)
|
121
|
+
thor (1.3.1)
|
122
|
+
unicode-display_width (2.5.0)
|
123
|
+
uri (0.13.0)
|
124
|
+
vcr (6.2.0)
|
125
|
+
vcr_better_binary (0.2.0)
|
126
|
+
vcr (>= 5.0)
|
127
|
+
webmock (3.23.1)
|
128
|
+
addressable (>= 2.8.0)
|
82
129
|
crack (>= 0.3.2)
|
83
130
|
hashdiff (>= 0.4.0, < 2.0.0)
|
84
|
-
yard (0.9.
|
131
|
+
yard (0.9.36)
|
85
132
|
|
86
133
|
PLATFORMS
|
134
|
+
arm64-darwin-22
|
87
135
|
ruby
|
136
|
+
x86_64-linux
|
88
137
|
|
89
138
|
DEPENDENCIES
|
90
|
-
appraisal
|
139
|
+
appraisal (~> 2.5)
|
91
140
|
bundler (~> 2.0)
|
92
|
-
|
93
|
-
|
94
|
-
pry
|
95
|
-
rake
|
141
|
+
pry (~> 0.14)
|
142
|
+
rake (~> 13.2)
|
96
143
|
remove_bg!
|
97
|
-
rspec (~> 3.
|
98
|
-
rspec-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
144
|
+
rspec (~> 3.13)
|
145
|
+
rspec-sonarqube-formatter (~> 1.5)
|
146
|
+
rspec-with_params (~> 0.3)
|
147
|
+
rspec_junit_formatter (~> 0.6)
|
148
|
+
rubocop (~> 1.64)
|
149
|
+
rubocop-performance (~> 1.21)
|
150
|
+
rubocop-rake (~> 0.6)
|
151
|
+
rubocop-rspec (~> 3.0)
|
152
|
+
simplecov (~> 0.22)
|
153
|
+
simplecov-cobertura (~> 2.1)
|
154
|
+
simplecov_json_formatter (~> 0.1)
|
155
|
+
vcr (~> 6.2)
|
156
|
+
vcr_better_binary (~> 0.2)
|
157
|
+
webmock (~> 3.23)
|
158
|
+
yard (~> 0.9)
|
105
159
|
|
106
160
|
BUNDLED WITH
|
107
|
-
2.
|
161
|
+
2.4.19
|
data/LICENSE.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
=====================
|
3
|
+
|
4
|
+
Copyright © 2019–2024 Canva Austria GmbH
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person
|
7
|
+
obtaining a copy of this software and associated documentation
|
8
|
+
files (the “Software”), to deal in the Software without
|
9
|
+
restriction, including without limitation the rights to use,
|
10
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
copies of the Software, and to permit persons to whom the
|
12
|
+
Software is furnished to do so, subject to the following
|
13
|
+
conditions:
|
14
|
+
|
15
|
+
The above copyright notice and this permission notice shall be
|
16
|
+
included in all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,14 +1,32 @@
|
|
1
|
-
[](https://www.remove.bg/)
|
2
2
|
|
3
|
-
# Ruby
|
3
|
+
# remove.bg Ruby Gem
|
4
4
|
|
5
|
-
|
5
|
+
<p align="center">
|
6
6
|
|
7
|
-
|
7
|
+
[](https://rubygems.org/gems/remove_bg)
|
8
|
+
[](https://rubygems.org/gems/remove_bg)
|
9
|
+
[](https://circleci.com/gh/remove-bg/ruby/tree/main)
|
10
|
+
[](https://github.com/remove-bg/ruby/blob/main/LICENSE.md)
|
11
|
+
[](https://app.codecov.io/gh/remove-bg/ruby)
|
12
|
+
[](https://sonarcloud.io/summary/overall?id=remove-bg_ruby)
|
13
|
+
[](https://sonarcloud.io/summary/overall?id=remove-bg_ruby)
|
14
|
+
[](https://github.com/remove-bg/ruby/network/dependencies)
|
15
|
+
|
16
|
+
</p>
|
17
|
+
|
18
|
+
## Requirements
|
19
|
+
|
20
|
+
This gem is compatible with Ruby 3.1+ and can be used with
|
21
|
+
[Faraday](https://rubygems.org/gems/faraday/) version 2 and above
|
22
|
+
|
23
|
+
An API key (free) from [remove.bg](https://www.remove.bg/api) is required.
|
24
|
+
|
25
|
+
## Quickstart Installation
|
8
26
|
|
9
27
|
Add the gem to your `Gemfile` and run `bundle install`:
|
10
28
|
|
11
|
-
```
|
29
|
+
```ruby
|
12
30
|
gem "remove_bg"
|
13
31
|
```
|
14
32
|
|
@@ -19,7 +37,7 @@ Please note the base configuration has the following resolution limits:
|
|
19
37
|
| Output format | Resolution limit |
|
20
38
|
|---------------|------------------|
|
21
39
|
| PNG | 10 megapixels |
|
22
|
-
| JPG |
|
40
|
+
| JPG | 50 megapixels |
|
23
41
|
|
24
42
|
## Full installation
|
25
43
|
|
@@ -30,8 +48,8 @@ Please install one of the following libraries:
|
|
30
48
|
- [GraphicsMagick](http://www.graphicsmagick.org/)
|
31
49
|
- [libvips](http://libvips.github.io/libvips/)
|
32
50
|
|
33
|
-
The gem will auto-detect any image processing libraries present. However you
|
34
|
-
|
51
|
+
The gem will auto-detect any image processing libraries present. However, you can
|
52
|
+
also explicitly configure which library to use:
|
35
53
|
|
36
54
|
```ruby
|
37
55
|
RemoveBg.configure do |config|
|
@@ -45,9 +63,9 @@ The full installation has the following resolution limits:
|
|
45
63
|
|
46
64
|
| Output format | Resolution limit |
|
47
65
|
|---------------|------------------|
|
48
|
-
| PNG |
|
49
|
-
| JPG |
|
50
|
-
| ZIP |
|
66
|
+
| PNG | 10 megapixels |
|
67
|
+
| JPG | 50 megapixels |
|
68
|
+
| ZIP | 50 megapixels |
|
51
69
|
|
52
70
|
# Usage
|
53
71
|
|
@@ -108,7 +126,8 @@ There's also a `#save` convenience method:
|
|
108
126
|
|
109
127
|
```ruby
|
110
128
|
result.save("processed/image.png")
|
111
|
-
|
129
|
+
# Overwrite any existing file
|
130
|
+
result.save!("processed/image.png")
|
112
131
|
```
|
113
132
|
|
114
133
|
## Producing transparent images over 10 megapixels
|
data/Rakefile
CHANGED
data/SECURITY.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Security Policy
|
2
|
+
|
3
|
+
We take the security of our software products and services seriously, including all of
|
4
|
+
the open source code repositories managed through our organization.
|
5
|
+
|
6
|
+
## Supported Versions
|
7
|
+
|
8
|
+
We currently support these versions of this library with security updates.
|
9
|
+
|
10
|
+
| Version | Supported |
|
11
|
+
| -------- | ------------------ |
|
12
|
+
| `2.x.x` | :white_check_mark: |
|
13
|
+
| `<= 1.5` | :x: |
|
14
|
+
|
15
|
+
## Reporting a Vulnerability
|
16
|
+
|
17
|
+
If you believe you have found a security vulnerability in this repository, please report
|
18
|
+
it to us through coordinated disclosure.
|
19
|
+
|
20
|
+
Please do not report security vulnerabilities through public GitHub issues, discussions,
|
21
|
+
or pull requests.
|
22
|
+
|
23
|
+
Instead, please contact us at https://www.remove.bg/support/contact
|
24
|
+
|
25
|
+
Please include as much of the information listed below as you can to help us better
|
26
|
+
understand and resolve the issue:
|
27
|
+
|
28
|
+
- The type of issue (e.g., buffer overflow, issue in a dependency,...)
|
29
|
+
- Full paths of source file(s) related to the manifestation of the issue
|
30
|
+
- The location of the affected source code (tag/branch/commit or direct URL)
|
31
|
+
- Any special configuration required to reproduce the issue
|
32
|
+
- Step-by-step instructions to reproduce the issue
|
33
|
+
- Proof-of-concept or exploit code (if possible)
|
34
|
+
- Impact of the issue, including how an attacker might exploit the issue
|
35
|
+
|
36
|
+
This information will help us triage your report more quickly.
|
data/lib/remove_bg/api.rb
CHANGED
data/lib/remove_bg/api_client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "json"
|
2
4
|
require "tempfile"
|
3
5
|
|
@@ -41,7 +43,7 @@ module RemoveBg
|
|
41
43
|
#
|
42
44
|
def remove_from_url(image_url, options)
|
43
45
|
RemoveBg::UrlValidator.validate(image_url)
|
44
|
-
data = options.data.merge(image_url:
|
46
|
+
data = options.data.merge(image_url:)
|
45
47
|
request_remove_bg(data, options.api_key)
|
46
48
|
end
|
47
49
|
|
@@ -70,26 +72,24 @@ module RemoveBg
|
|
70
72
|
# Faraday v0.16 & v1.0+ support streaming, v0.17 did not (rollback release)
|
71
73
|
if req.options.respond_to?(:on_data)
|
72
74
|
streaming = true
|
73
|
-
req.options.on_data =
|
75
|
+
req.options.on_data = proc do |chunk, _|
|
74
76
|
download.write(chunk)
|
75
77
|
end
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
79
|
-
# Faraday v0.
|
80
|
-
|
81
|
-
download.write(response.body)
|
82
|
-
end
|
81
|
+
# Faraday v0.17
|
82
|
+
download.write(response.body) unless streaming
|
83
83
|
|
84
84
|
download.rewind
|
85
85
|
|
86
86
|
if response.status == 200
|
87
|
-
parse_image_result(headers: response.headers, download:
|
87
|
+
parse_image_result(headers: response.headers, download:)
|
88
88
|
else
|
89
89
|
response_body = download.read
|
90
90
|
download.close
|
91
91
|
download.unlink
|
92
|
-
handle_http_error(response
|
92
|
+
handle_http_error(response:, body: response_body)
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
@@ -101,7 +101,7 @@ module RemoveBg
|
|
101
101
|
if response.status == 200
|
102
102
|
parse_account_result(response)
|
103
103
|
else
|
104
|
-
handle_http_error(response
|
104
|
+
handle_http_error(response:, body: response.body)
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
@@ -123,7 +123,7 @@ module RemoveBg
|
|
123
123
|
|
124
124
|
def parse_image_result(headers:, download:)
|
125
125
|
result_for_content_type(headers["Content-Type"]).new(
|
126
|
-
download
|
126
|
+
download:,
|
127
127
|
metadata: ResultMetadata.new(headers),
|
128
128
|
rate_limit: RateLimitInfo.new(headers)
|
129
129
|
)
|
@@ -139,8 +139,8 @@ module RemoveBg
|
|
139
139
|
|
140
140
|
def parse_account_result(response)
|
141
141
|
attributes = JSON.parse(response.body, symbolize_names: true)
|
142
|
-
|
143
|
-
|
142
|
+
.fetch(:data)
|
143
|
+
.fetch(:attributes)
|
144
144
|
|
145
145
|
RemoveBg::AccountInfo.new(attributes)
|
146
146
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "result"
|
2
4
|
|
3
5
|
module RemoveBg
|
@@ -13,13 +15,22 @@ module RemoveBg
|
|
13
15
|
# @return [nil]
|
14
16
|
#
|
15
17
|
def save_zip(file_path, overwrite: false)
|
16
|
-
if File.exist?(file_path) && !overwrite
|
17
|
-
|
18
|
-
|
18
|
+
raise FileOverwriteError.new(file_path) if File.exist?(file_path) && !overwrite
|
19
|
+
|
20
|
+
warn("DEPRECATION WARNING: overwrite: true is deprecated and will be removed from remove_bg 2.0 (use save_zip! instead)") if overwrite
|
19
21
|
|
20
22
|
FileUtils.cp(download, file_path)
|
21
23
|
end
|
22
24
|
|
25
|
+
# Saves the ZIP archive containing the alpha.png and color.jpg files, overwriting any exisiting files
|
26
|
+
# (useful if you want to handle composition yourself)
|
27
|
+
# @param file_path [string]
|
28
|
+
# @return [nil]
|
29
|
+
#
|
30
|
+
def save_zip!(file_path)
|
31
|
+
FileUtils.cp(download, file_path)
|
32
|
+
end
|
33
|
+
|
23
34
|
private
|
24
35
|
|
25
36
|
def image_file
|
@@ -27,10 +38,8 @@ module RemoveBg
|
|
27
38
|
end
|
28
39
|
|
29
40
|
def composite_file
|
30
|
-
@composite_file ||=
|
31
|
-
|
32
|
-
.tap { |file| compose_to_file(file) }
|
33
|
-
end
|
41
|
+
@composite_file ||= binary_tempfile(["composed", ".png"])
|
42
|
+
.tap { |file| compose_to_file(file) }
|
34
43
|
end
|
35
44
|
|
36
45
|
def color_file
|
@@ -45,8 +54,8 @@ module RemoveBg
|
|
45
54
|
extract_parts
|
46
55
|
|
47
56
|
ImageComposer.new.compose(
|
48
|
-
color_file
|
49
|
-
alpha_file
|
57
|
+
color_file:,
|
58
|
+
alpha_file:,
|
50
59
|
destination_path: destination.path
|
51
60
|
)
|
52
61
|
end
|
@@ -59,7 +68,7 @@ module RemoveBg
|
|
59
68
|
end
|
60
69
|
|
61
70
|
def binary_tempfile(basename)
|
62
|
-
Tempfile.new(basename).tap
|
71
|
+
Tempfile.new(basename).tap(&:binmode)
|
63
72
|
end
|
64
73
|
end
|
65
74
|
end
|