imgproxy 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +235 -112
  3. data/lib/imgproxy.rb +70 -50
  4. data/lib/imgproxy/builder.rb +47 -55
  5. data/lib/imgproxy/config.rb +96 -30
  6. data/lib/imgproxy/extensions/active_storage.rb +10 -0
  7. data/lib/imgproxy/extensions/shrine.rb +10 -0
  8. data/lib/imgproxy/options.rb +83 -121
  9. data/lib/imgproxy/options_aliases.rb +43 -0
  10. data/lib/imgproxy/options_casters/adjust.rb +22 -0
  11. data/lib/imgproxy/options_casters/array.rb +12 -0
  12. data/lib/imgproxy/options_casters/base64.rb +12 -0
  13. data/lib/imgproxy/options_casters/bool.rb +12 -0
  14. data/lib/imgproxy/options_casters/crop.rb +23 -0
  15. data/lib/imgproxy/options_casters/extend.rb +26 -0
  16. data/lib/imgproxy/options_casters/float.rb +16 -0
  17. data/lib/imgproxy/options_casters/gif_options.rb +21 -0
  18. data/lib/imgproxy/options_casters/gravity.rb +23 -0
  19. data/lib/imgproxy/options_casters/group.rb +21 -0
  20. data/lib/imgproxy/options_casters/integer.rb +10 -0
  21. data/lib/imgproxy/options_casters/jpeg_options.rb +26 -0
  22. data/lib/imgproxy/options_casters/png_options.rb +23 -0
  23. data/lib/imgproxy/options_casters/resize.rb +21 -0
  24. data/lib/imgproxy/options_casters/size.rb +24 -0
  25. data/lib/imgproxy/options_casters/string.rb +10 -0
  26. data/lib/imgproxy/options_casters/trim.rb +28 -0
  27. data/lib/imgproxy/options_casters/watermark.rb +30 -0
  28. data/lib/imgproxy/trim_array.rb +11 -0
  29. data/lib/imgproxy/url_adapters.rb +0 -4
  30. data/lib/imgproxy/url_adapters/active_storage.rb +25 -0
  31. data/lib/imgproxy/url_adapters/shrine.rb +15 -5
  32. data/lib/imgproxy/version.rb +1 -1
  33. metadata +54 -9
  34. data/lib/imgproxy/url_adapters/active_storage_gcs.rb +0 -31
  35. data/lib/imgproxy/url_adapters/active_storage_s3.rb +0 -23
  36. data/lib/imgproxy/url_adapters/shrine_s3.rb +0 -21
@@ -1,9 +1,5 @@
1
1
  require "imgproxy/url_adapters/active_storage"
2
- require "imgproxy/url_adapters/active_storage_s3"
3
- require "imgproxy/url_adapters/active_storage_gcs"
4
-
5
2
  require "imgproxy/url_adapters/shrine"
6
- require "imgproxy/url_adapters/shrine_s3"
7
3
 
8
4
  module Imgproxy
9
5
  # URL adapters config. Allows to use this gem with ActiveStorage, Shrine, etc.
@@ -15,8 +15,33 @@ module Imgproxy
15
15
  end
16
16
 
17
17
  def url(image)
18
+ return s3_url(image) if use_s3_url(image)
19
+ return gcs_url(image) if use_gcs_url(image)
20
+
18
21
  Rails.application.routes.url_helpers.url_for(image)
19
22
  end
23
+
24
+ private
25
+
26
+ def s3_url(image)
27
+ "s3://#{image.service.bucket.name}/#{image.key}"
28
+ end
29
+
30
+ def use_s3_url(image)
31
+ config.use_s3_urls && image.service.is_a?(::ActiveStorage::Service::S3Service)
32
+ end
33
+
34
+ def gcs_url(image)
35
+ "gs://#{config.gcs_bucket}/#{image.key}"
36
+ end
37
+
38
+ def use_gcs_url(image)
39
+ config.use_gcs_urls && image.service.is_a?(::ActiveStorage::Service::GCSService)
40
+ end
41
+
42
+ def config
43
+ Imgproxy.config
44
+ end
20
45
  end
21
46
  end
22
47
  end
@@ -8,19 +8,29 @@ module Imgproxy
8
8
  #
9
9
  # Imgproxy.url_for(user.avatar)
10
10
  class Shrine
11
- def initialize(host: nil)
12
- @host = host
13
- end
14
-
15
11
  def applicable?(image)
16
12
  image.is_a?(::Shrine::UploadedFile)
17
13
  end
18
14
 
19
15
  def url(image)
16
+ return s3_url(image) if use_s3_url(image)
17
+
20
18
  opts = {}
21
- opts[:host] = @host if @host
19
+ opts[:host] = Imgproxy.config.shrine_host if Imgproxy.config.shrine_host
22
20
  image.url(opts)
23
21
  end
22
+
23
+ private
24
+
25
+ def s3_url(image)
26
+ path = [*image.storage.prefix, image.id].join("/")
27
+ "s3://#{image.storage.bucket.name}/#{path}"
28
+ end
29
+
30
+ def use_s3_url(image)
31
+ Imgproxy.config.use_s3_urls &&
32
+ image.storage.is_a?(::Shrine::Storage::S3)
33
+ end
24
34
  end
25
35
  end
26
36
  end
@@ -1,3 +1,3 @@
1
1
  module Imgproxy
2
- VERSION = "1.2.0".freeze
2
+ VERSION = "2.0.0".freeze
3
3
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imgproxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Alexandrovich
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-11 00:00:00.000000000 Z
11
+ date: 2021-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: anyway_config
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: benchmark-memory
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.2
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: pry-byebug
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -164,18 +192,35 @@ files:
164
192
  - lib/imgproxy/extensions/active_storage.rb
165
193
  - lib/imgproxy/extensions/shrine.rb
166
194
  - lib/imgproxy/options.rb
195
+ - lib/imgproxy/options_aliases.rb
196
+ - lib/imgproxy/options_casters/adjust.rb
197
+ - lib/imgproxy/options_casters/array.rb
198
+ - lib/imgproxy/options_casters/base64.rb
199
+ - lib/imgproxy/options_casters/bool.rb
200
+ - lib/imgproxy/options_casters/crop.rb
201
+ - lib/imgproxy/options_casters/extend.rb
202
+ - lib/imgproxy/options_casters/float.rb
203
+ - lib/imgproxy/options_casters/gif_options.rb
204
+ - lib/imgproxy/options_casters/gravity.rb
205
+ - lib/imgproxy/options_casters/group.rb
206
+ - lib/imgproxy/options_casters/integer.rb
207
+ - lib/imgproxy/options_casters/jpeg_options.rb
208
+ - lib/imgproxy/options_casters/png_options.rb
209
+ - lib/imgproxy/options_casters/resize.rb
210
+ - lib/imgproxy/options_casters/size.rb
211
+ - lib/imgproxy/options_casters/string.rb
212
+ - lib/imgproxy/options_casters/trim.rb
213
+ - lib/imgproxy/options_casters/watermark.rb
214
+ - lib/imgproxy/trim_array.rb
167
215
  - lib/imgproxy/url_adapters.rb
168
216
  - lib/imgproxy/url_adapters/active_storage.rb
169
- - lib/imgproxy/url_adapters/active_storage_gcs.rb
170
- - lib/imgproxy/url_adapters/active_storage_s3.rb
171
217
  - lib/imgproxy/url_adapters/shrine.rb
172
- - lib/imgproxy/url_adapters/shrine_s3.rb
173
218
  - lib/imgproxy/version.rb
174
219
  homepage: https://github.com/imgproxy/imgproxy.rb
175
220
  licenses:
176
221
  - MIT
177
222
  metadata: {}
178
- post_install_message:
223
+ post_install_message:
179
224
  rdoc_options: []
180
225
  require_paths:
181
226
  - lib
@@ -183,7 +228,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
228
  requirements:
184
229
  - - ">="
185
230
  - !ruby/object:Gem::Version
186
- version: '2.0'
231
+ version: '2.5'
187
232
  required_rubygems_version: !ruby/object:Gem::Requirement
188
233
  requirements:
189
234
  - - ">="
@@ -191,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
236
  version: '0'
192
237
  requirements: []
193
238
  rubygems_version: 3.0.3
194
- signing_key:
239
+ signing_key:
195
240
  specification_version: 4
196
241
  summary: imgproxy URL generator
197
242
  test_files: []
@@ -1,31 +0,0 @@
1
- require "imgproxy/url_adapters/active_storage"
2
-
3
- module Imgproxy
4
- class UrlAdapters
5
- # Adapter for ActiveStorage with S3 service
6
- #
7
- # Imgproxy.configure do |config|
8
- # config.url_adapters.add Imgproxy::UrlAdapters::ActiveStorageGCS.new("bucket_name")
9
- # end
10
- #
11
- # Imgproxy.url_for(user.avatar)
12
- class ActiveStorageGCS < Imgproxy::UrlAdapters::ActiveStorage
13
- # @param [String] bucket_name Google Cloud Storage bucket name
14
- def initialize(bucket_name)
15
- @bucket_name = bucket_name
16
- end
17
-
18
- # @return [String] Google Cloud Storage bucket name
19
- attr_reader :bucket_name
20
-
21
- def applicable?(image)
22
- super &&
23
- image.service.is_a?(::ActiveStorage::Service::GCSService)
24
- end
25
-
26
- def url(image)
27
- "gs://#{bucket_name}/#{image.key}"
28
- end
29
- end
30
- end
31
- end
@@ -1,23 +0,0 @@
1
- require "imgproxy/url_adapters/active_storage"
2
-
3
- module Imgproxy
4
- class UrlAdapters
5
- # Adapter for ActiveStorage with S3 service
6
- #
7
- # Imgproxy.configure do |config|
8
- # config.url_adapters.add Imgproxy::UrlAdapters::ActiveStorageS3.new
9
- # end
10
- #
11
- # Imgproxy.url_for(user.avatar)
12
- class ActiveStorageS3 < Imgproxy::UrlAdapters::ActiveStorage
13
- def applicable?(image)
14
- super &&
15
- image.service.is_a?(::ActiveStorage::Service::S3Service)
16
- end
17
-
18
- def url(image)
19
- "s3://#{image.service.bucket.name}/#{image.key}"
20
- end
21
- end
22
- end
23
- end
@@ -1,21 +0,0 @@
1
- module Imgproxy
2
- class UrlAdapters
3
- # Adapter for Shrine with S3 storage
4
- #
5
- # Imgproxy.configure do |config|
6
- # config.url_adapters.add Imgproxy::UrlAdapters::ShrineS3.new
7
- # end
8
- #
9
- # Imgproxy.url_for(user.avatar)
10
- class ShrineS3 < Imgproxy::UrlAdapters::Shrine
11
- def applicable?(image)
12
- super && image.storage.is_a?(::Shrine::Storage::S3)
13
- end
14
-
15
- def url(image)
16
- path = [*image.storage.prefix, image.id].join("/")
17
- "s3://#{image.storage.bucket.name}/#{path}"
18
- end
19
- end
20
- end
21
- end