imgproxy 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +8 -0
  3. data/CHANGELOG.md +74 -0
  4. data/README.md +176 -135
  5. data/UPGRADE.md +136 -0
  6. data/docs/info_options.md +223 -0
  7. data/docs/processing_options.md +724 -0
  8. data/docs/yard/fix_pictures.rb +25 -0
  9. data/docs/yard/github_alerts.rb +16 -0
  10. data/docs/yard/relative_markdown_links.rb +31 -0
  11. data/lib/imgproxy/config.rb +96 -41
  12. data/lib/imgproxy/extensions/active_storage.rb +6 -4
  13. data/lib/imgproxy/extensions/shrine.rb +6 -4
  14. data/lib/imgproxy/option_aliases/info.rb +33 -0
  15. data/lib/imgproxy/option_aliases/processing.rb +74 -0
  16. data/lib/imgproxy/options_builders/base.rb +54 -0
  17. data/lib/imgproxy/options_builders/info.rb +52 -0
  18. data/lib/imgproxy/options_builders/processing.rb +150 -0
  19. data/lib/imgproxy/options_casters/adjust.rb +3 -1
  20. data/lib/imgproxy/options_casters/alpha.rb +27 -0
  21. data/lib/imgproxy/options_casters/array.rb +3 -1
  22. data/lib/imgproxy/options_casters/autoquality.rb +28 -0
  23. data/lib/imgproxy/options_casters/average.rb +27 -0
  24. data/lib/imgproxy/options_casters/background.rb +27 -0
  25. data/lib/imgproxy/options_casters/base64.rb +2 -0
  26. data/lib/imgproxy/options_casters/blur_detections.rb +28 -0
  27. data/lib/imgproxy/options_casters/blurhash.rb +21 -0
  28. data/lib/imgproxy/options_casters/bool.rb +3 -1
  29. data/lib/imgproxy/options_casters/crop.rb +3 -1
  30. data/lib/imgproxy/options_casters/dominant_colors.rb +27 -0
  31. data/lib/imgproxy/options_casters/draw_detections.rb +28 -0
  32. data/lib/imgproxy/options_casters/extend.rb +3 -1
  33. data/lib/imgproxy/options_casters/filename.rb +31 -0
  34. data/lib/imgproxy/options_casters/float.rb +3 -1
  35. data/lib/imgproxy/options_casters/format_quality.rb +19 -0
  36. data/lib/imgproxy/options_casters/gradient.rb +31 -0
  37. data/lib/imgproxy/options_casters/gravity.rb +20 -6
  38. data/lib/imgproxy/options_casters/group.rb +2 -0
  39. data/lib/imgproxy/options_casters/hashsum.rb +24 -0
  40. data/lib/imgproxy/options_casters/integer.rb +2 -0
  41. data/lib/imgproxy/options_casters/jpeg_options.rb +3 -1
  42. data/lib/imgproxy/options_casters/padding.rb +41 -0
  43. data/lib/imgproxy/options_casters/png_options.rb +3 -1
  44. data/lib/imgproxy/options_casters/resize.rb +3 -1
  45. data/lib/imgproxy/options_casters/size.rb +3 -1
  46. data/lib/imgproxy/options_casters/string.rb +2 -0
  47. data/lib/imgproxy/options_casters/trim.rb +3 -1
  48. data/lib/imgproxy/options_casters/unsharp_masking.rb +25 -0
  49. data/lib/imgproxy/options_casters/video_thumbnail_tile.rb +34 -0
  50. data/lib/imgproxy/options_casters/watermark.rb +5 -4
  51. data/lib/imgproxy/options_casters/watermark_size.rb +21 -0
  52. data/lib/imgproxy/options_casters/{gif_options.rb → webp_options.rb} +6 -5
  53. data/lib/imgproxy/options_casters/zoom.rb +27 -0
  54. data/lib/imgproxy/service_config.rb +111 -0
  55. data/lib/imgproxy/trim_array.rb +2 -0
  56. data/lib/imgproxy/url_adapters/active_storage.rb +2 -0
  57. data/lib/imgproxy/url_adapters/shrine.rb +8 -2
  58. data/lib/imgproxy/url_adapters.rb +3 -0
  59. data/lib/imgproxy/url_builders/base.rb +184 -0
  60. data/lib/imgproxy/url_builders/info.rb +44 -0
  61. data/lib/imgproxy/url_builders/processing.rb +59 -0
  62. data/lib/imgproxy/version.rb +3 -1
  63. data/lib/imgproxy.rb +19 -57
  64. data/logo/logo-dark.svg +22 -0
  65. data/logo/logo-light.svg +31 -0
  66. metadata +70 -32
  67. data/lib/imgproxy/builder.rb +0 -140
  68. data/lib/imgproxy/options.rb +0 -119
  69. data/lib/imgproxy/options_aliases.rb +0 -45
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Imgproxy
2
4
  module OptionsCasters
3
5
  # Casts array option
@@ -5,7 +7,7 @@ module Imgproxy
5
7
  def self.cast(raw)
6
8
  return if raw.nil?
7
9
 
8
- raw.is_a?(Array) ? raw : [raw]
10
+ raw.is_a?(::Array) ? raw : [raw]
9
11
  end
10
12
  end
11
13
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "imgproxy/options_casters/group"
4
+ require "imgproxy/options_casters/string"
5
+ require "imgproxy/options_casters/integer"
6
+ require "imgproxy/options_casters/float"
7
+
8
+ module Imgproxy
9
+ module OptionsCasters
10
+ # Casts `autoquality` processing option
11
+ module Autoquality
12
+ CASTER = Imgproxy::OptionsCasters::Group.new(
13
+ method: Imgproxy::OptionsCasters::String,
14
+ target: Imgproxy::OptionsCasters::Float,
15
+ min_quality: Imgproxy::OptionsCasters::Integer,
16
+ max_quality: Imgproxy::OptionsCasters::Integer,
17
+ allowed_error: Imgproxy::OptionsCasters::Float,
18
+ ).freeze
19
+
20
+ def self.cast(raw)
21
+ return raw unless raw.is_a?(Hash)
22
+
23
+ values = CASTER.cast(raw)
24
+ (values[0] == "none") ? "none" : values
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "imgproxy/options_casters/group"
4
+ require "imgproxy/options_casters/bool"
5
+
6
+ module Imgproxy
7
+ module OptionsCasters
8
+ # Casts `average` info option
9
+ module Average
10
+ CASTER = Imgproxy::OptionsCasters::Group.new(
11
+ average: Imgproxy::OptionsCasters::Bool,
12
+ ignore_transparent: Imgproxy::OptionsCasters::Bool,
13
+ ).freeze
14
+
15
+ def self.cast(raw)
16
+ # Allow average to be just a boolean
17
+ return Imgproxy::OptionsCasters::Bool.cast(raw) if [true, false].include?(raw)
18
+
19
+ return raw unless raw.is_a?(Hash)
20
+ return if raw[:average].nil?
21
+
22
+ values = CASTER.cast(raw)
23
+ values[0].zero? ? 0 : values
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "imgproxy/options_casters/group"
4
+ require "imgproxy/options_casters/integer"
5
+ require "imgproxy/options_casters/string"
6
+
7
+ module Imgproxy
8
+ module OptionsCasters
9
+ # Casts `background` info option
10
+ module Background
11
+ CASTER = Imgproxy::OptionsCasters::Group.new(
12
+ r: Imgproxy::OptionsCasters::Integer,
13
+ g: Imgproxy::OptionsCasters::Integer,
14
+ b: Imgproxy::OptionsCasters::Integer,
15
+ ).freeze
16
+
17
+ def self.cast(raw)
18
+ return raw.map { |v| Imgproxy::OptionsCasters::Integer.cast(v) } if raw.is_a?(::Array)
19
+
20
+ return raw unless raw.is_a?(Hash)
21
+ return Imgproxy::OptionsCasters::String.cast(raw[:hex_color]) if raw.key?(:hex_color)
22
+
23
+ CASTER.cast(raw)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "base64"
2
4
 
3
5
  module Imgproxy
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "imgproxy/trim_array"
4
+ require "imgproxy/options_casters/float"
5
+ require "imgproxy/options_casters/array"
6
+
7
+ module Imgproxy
8
+ module OptionsCasters
9
+ # Casts `blur_detections` processing option
10
+ module BlurDetections
11
+ using TrimArray
12
+
13
+ def self.cast(raw)
14
+ # Allow blur_detections to be just a numeric
15
+ return Imgproxy::OptionsCasters::Float.cast(raw) if raw.is_a?(Numeric)
16
+
17
+ return raw unless raw.is_a?(Hash)
18
+ return unless raw[:sigma]
19
+
20
+ values = [
21
+ Imgproxy::OptionsCasters::Float.cast(raw[:sigma]),
22
+ *Imgproxy::OptionsCasters::Array.cast(raw[:class_names]),
23
+ ].trim!
24
+ values[0].zero? ? 0 : values
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "imgproxy/options_casters/group"
4
+ require "imgproxy/options_casters/integer"
5
+
6
+ module Imgproxy
7
+ module OptionsCasters
8
+ # Casts `blurhash` info option
9
+ module Blurhash
10
+ CASTER = Imgproxy::OptionsCasters::Group.new(
11
+ x_components: Imgproxy::OptionsCasters::Integer,
12
+ y_components: Imgproxy::OptionsCasters::Integer,
13
+ ).freeze
14
+
15
+ def self.cast(raw)
16
+ return raw unless raw.is_a?(Hash)
17
+ CASTER.cast(raw)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Imgproxy
2
4
  module OptionsCasters
3
5
  # Casts boolean option
@@ -5,7 +7,7 @@ module Imgproxy
5
7
  def self.cast(raw)
6
8
  return if raw.nil?
7
9
 
8
- raw && raw != 0 && raw != "0" ? 1 : 0
10
+ (raw && raw != 0 && raw != "0") ? 1 : 0
9
11
  end
10
12
  end
11
13
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "imgproxy/trim_array"
2
4
  require "imgproxy/options_casters/float"
3
5
  require "imgproxy/options_casters/gravity"
4
6
 
5
7
  module Imgproxy
6
8
  module OptionsCasters
7
- # Casts crop option
9
+ # Casts `crop` processing/info option
8
10
  module Crop
9
11
  using TrimArray
10
12
 
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "imgproxy/options_casters/group"
4
+ require "imgproxy/options_casters/bool"
5
+
6
+ module Imgproxy
7
+ module OptionsCasters
8
+ # Casts `dominant_colors` info option
9
+ module DominantColors
10
+ CASTER = Imgproxy::OptionsCasters::Group.new(
11
+ dominant_colors: Imgproxy::OptionsCasters::Bool,
12
+ build_missed: Imgproxy::OptionsCasters::Bool,
13
+ ).freeze
14
+
15
+ def self.cast(raw)
16
+ # Allow dominant_colors to be just a boolean
17
+ return Imgproxy::OptionsCasters::Bool.cast(raw) if [true, false].include?(raw)
18
+
19
+ return raw unless raw.is_a?(Hash)
20
+ return if raw[:dominant_colors].nil?
21
+
22
+ values = CASTER.cast(raw)
23
+ values[0].zero? ? 0 : values
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "imgproxy/trim_array"
4
+ require "imgproxy/options_casters/bool"
5
+ require "imgproxy/options_casters/array"
6
+
7
+ module Imgproxy
8
+ module OptionsCasters
9
+ # Casts `draw_detections` processing option
10
+ module DrawDetections
11
+ using TrimArray
12
+
13
+ def self.cast(raw)
14
+ # Allow draw_detections to be just a boolean
15
+ return Imgproxy::OptionsCasters::Bool.cast(raw) if [true, false].include?(raw)
16
+
17
+ return raw unless raw.is_a?(Hash)
18
+ return unless raw[:draw]
19
+
20
+ values = [
21
+ Imgproxy::OptionsCasters::Bool.cast(raw[:draw]),
22
+ *Imgproxy::OptionsCasters::Array.cast(raw[:class_names]),
23
+ ].trim!
24
+ values[0].zero? ? 0 : values
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "imgproxy/options_casters/group"
2
4
  require "imgproxy/options_casters/bool"
3
5
  require "imgproxy/options_casters/gravity"
4
6
 
5
7
  module Imgproxy
6
8
  module OptionsCasters
7
- # Casts extend option
9
+ # Casts `extend` processing option
8
10
  module Extend
9
11
  CASTER = Imgproxy::OptionsCasters::Group.new(
10
12
  extend: Imgproxy::OptionsCasters::Bool,
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "imgproxy/options_casters/group"
4
+ require "imgproxy/options_casters/string"
5
+ require "imgproxy/options_casters/bool"
6
+ require "imgproxy/options_casters/base64"
7
+
8
+ module Imgproxy
9
+ module OptionsCasters
10
+ # Casts `filename` processing option
11
+ module Filename
12
+ CASTER = Imgproxy::OptionsCasters::Group.new(
13
+ filename: Imgproxy::OptionsCasters::String,
14
+ encoded: Imgproxy::OptionsCasters::Bool,
15
+ ).freeze
16
+
17
+ def self.cast(raw)
18
+ return raw unless raw.is_a?(Hash)
19
+ return if raw[:filename].nil?
20
+
21
+ encoded = Imgproxy::OptionsCasters::Bool.cast(raw[:encoded])
22
+
23
+ if encoded.nil? || encoded.zero?
24
+ return Imgproxy::OptionsCasters::String.cast(raw[:filename])
25
+ end
26
+
27
+ [Imgproxy::OptionsCasters::Base64.cast(raw[:filename]), 1]
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Imgproxy
2
4
  module OptionsCasters
3
5
  # Casts float option
@@ -8,7 +10,7 @@ module Imgproxy
8
10
  raw&.to_f&.then do |f|
9
11
  # Convert integral value to Integer so to_s won't give us trailing zero
10
12
  i = f.to_i
11
- i == f ? i : f
13
+ (i == f) ? i : f
12
14
  end
13
15
  end
14
16
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "imgproxy/options_casters/integer"
4
+
5
+ module Imgproxy
6
+ module OptionsCasters
7
+ # Casts `format_quality` info option
8
+ module FormatQuality
9
+ def self.cast(raw)
10
+ return raw unless raw.is_a?(Hash)
11
+
12
+ raw.flat_map do |format, quality|
13
+ next if quality.nil?
14
+ [format.to_s, Imgproxy::OptionsCasters::Integer.cast(quality)]
15
+ end.compact
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "imgproxy/options_casters/group"
4
+ require "imgproxy/options_casters/float"
5
+ require "imgproxy/options_casters/string"
6
+
7
+ module Imgproxy
8
+ module OptionsCasters
9
+ # Casts `gradient` processing option
10
+ module Gradient
11
+ CASTER = Imgproxy::OptionsCasters::Group.new(
12
+ opacity: Imgproxy::OptionsCasters::Float,
13
+ color: Imgproxy::OptionsCasters::String,
14
+ direction: Imgproxy::OptionsCasters::String,
15
+ start: Imgproxy::OptionsCasters::Float,
16
+ stop: Imgproxy::OptionsCasters::Float,
17
+ ).freeze
18
+
19
+ def self.cast(raw)
20
+ # Allow gradient to be just a numeric
21
+ return Imgproxy::OptionsCasters::Float.cast(raw) if raw.is_a?(Numeric)
22
+
23
+ return raw unless raw.is_a?(Hash)
24
+ return if raw[:opacity].nil?
25
+
26
+ values = CASTER.cast(raw)
27
+ values[0].zero? ? 0 : values
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,22 +1,36 @@
1
- require "imgproxy/options_casters/group"
1
+ # frozen_string_literal: true
2
+
3
+ require "imgproxy/trim_array"
2
4
  require "imgproxy/options_casters/string"
5
+ require "imgproxy/options_casters/group"
6
+ require "imgproxy/options_casters/array"
3
7
  require "imgproxy/options_casters/float"
4
8
 
5
9
  module Imgproxy
6
10
  module OptionsCasters
7
- # Casts gravity option
11
+ # Casts `gravity` processing option
8
12
  module Gravity
9
- CASTER = Imgproxy::OptionsCasters::Group.new(
10
- type: Imgproxy::OptionsCasters::String,
13
+ using TrimArray
14
+
15
+ CLASS_NAMES_CASTER = Imgproxy::OptionsCasters::Group.new(
16
+ class_names: Imgproxy::OptionsCasters::Array,
17
+ )
18
+ OFFSETS_CASTER = Imgproxy::OptionsCasters::Group.new(
11
19
  x_offset: Imgproxy::OptionsCasters::Float,
12
20
  y_offset: Imgproxy::OptionsCasters::Float,
13
- ).freeze
21
+ )
14
22
 
15
23
  def self.cast(raw)
16
24
  return raw unless raw.is_a?(Hash)
17
25
  return unless raw[:type]
18
26
 
19
- CASTER.cast(raw)
27
+ type = Imgproxy::OptionsCasters::String.cast(raw[:type])
28
+
29
+ case type
30
+ when "sm" then type
31
+ when "obj" then [type, *CLASS_NAMES_CASTER.cast(raw)].trim!
32
+ else [type, *OFFSETS_CASTER.cast(raw)].trim!
33
+ end
20
34
  end
21
35
  end
22
36
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "imgproxy/trim_array"
2
4
 
3
5
  module Imgproxy
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "imgproxy/options_casters/group"
4
+ require "imgproxy/options_casters/string"
5
+
6
+ module Imgproxy
7
+ module OptionsCasters
8
+ # Casts `hashsum` info option
9
+ module Hashsum
10
+ CASTER = Imgproxy::OptionsCasters::Group.new(
11
+ hashsum_type: Imgproxy::OptionsCasters::String,
12
+ hashsum: Imgproxy::OptionsCasters::String,
13
+ ).freeze
14
+
15
+ def self.cast(raw)
16
+ return raw unless raw.is_a?(Hash)
17
+ return if raw[:hashsum_type].nil?
18
+
19
+ values = CASTER.cast(raw)
20
+ (values[0] == "none") ? "none" : values
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Imgproxy
2
4
  module OptionsCasters
3
5
  # Casts integer option
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "imgproxy/options_casters/group"
2
4
  require "imgproxy/options_casters/bool"
3
5
  require "imgproxy/options_casters/integer"
4
6
 
5
7
  module Imgproxy
6
8
  module OptionsCasters
7
- # Casts jpeg_options option
9
+ # Casts `jpeg_options` processing option
8
10
  module JpegOptions
9
11
  CASTER = Imgproxy::OptionsCasters::Group.new(
10
12
  progressive: Imgproxy::OptionsCasters::Bool,
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "imgproxy/options_casters/group"
4
+ require "imgproxy/options_casters/integer"
5
+
6
+ module Imgproxy
7
+ module OptionsCasters
8
+ # Casts `padding` info option
9
+ module Padding
10
+ CASTER = Imgproxy::OptionsCasters::Group.new(
11
+ top: Imgproxy::OptionsCasters::Integer,
12
+ right: Imgproxy::OptionsCasters::Integer,
13
+ bottom: Imgproxy::OptionsCasters::Integer,
14
+ left: Imgproxy::OptionsCasters::Integer,
15
+ ).freeze
16
+
17
+ def self.cast(raw)
18
+ # Allow padding to be just a number
19
+ return Imgproxy::OptionsCasters::Integer.cast(raw) if raw.is_a?(Numeric)
20
+
21
+ return raw.map { |v| Imgproxy::OptionsCasters::Integer.cast(v) } if raw.is_a?(::Array)
22
+
23
+ return raw unless raw.is_a?(Hash)
24
+
25
+ compact CASTER.cast(raw)
26
+ end
27
+
28
+ def self.compact(values)
29
+ if values[0] == values[1] && values[0] == values[2] && values[0] == values[3]
30
+ return values[0]
31
+ end
32
+
33
+ return values[0, 2] if values[0] == values[2] && values[1] == values[3]
34
+
35
+ return values[0, 3] if values[1] == values[3]
36
+
37
+ values
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "imgproxy/options_casters/group"
2
4
  require "imgproxy/options_casters/bool"
3
5
  require "imgproxy/options_casters/integer"
4
6
 
5
7
  module Imgproxy
6
8
  module OptionsCasters
7
- # Casts png_options option
9
+ # Casts `png_options` processing option
8
10
  module PngOptions
9
11
  CASTER = Imgproxy::OptionsCasters::Group.new(
10
12
  interlaced: Imgproxy::OptionsCasters::Bool,
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "imgproxy/trim_array"
2
4
  require "imgproxy/options_casters/string"
3
5
  require "imgproxy/options_casters/size"
4
6
 
5
7
  module Imgproxy
6
8
  module OptionsCasters
7
- # Casts resize option
9
+ # Casts `resize` processing option
8
10
  module Resize
9
11
  using TrimArray
10
12
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "imgproxy/trim_array"
2
4
  require "imgproxy/options_casters/integer"
3
5
  require "imgproxy/options_casters/bool"
@@ -5,7 +7,7 @@ require "imgproxy/options_casters/extend"
5
7
 
6
8
  module Imgproxy
7
9
  module OptionsCasters
8
- # Casts size option
10
+ # Casts `size` processing option
9
11
  module Size
10
12
  using TrimArray
11
13
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Imgproxy
2
4
  module OptionsCasters
3
5
  # Casts string option
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "imgproxy/options_casters/group"
2
4
  require "imgproxy/options_casters/float"
3
5
  require "imgproxy/options_casters/string"
@@ -5,7 +7,7 @@ require "imgproxy/options_casters/bool"
5
7
 
6
8
  module Imgproxy
7
9
  module OptionsCasters
8
- # Casts trim option
10
+ # Casts `trim` processing option
9
11
  module Trim
10
12
  CASTER = Imgproxy::OptionsCasters::Group.new(
11
13
  threshold: Imgproxy::OptionsCasters::Float,
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "imgproxy/options_casters/group"
4
+ require "imgproxy/options_casters/string"
5
+ require "imgproxy/options_casters/float"
6
+
7
+ module Imgproxy
8
+ module OptionsCasters
9
+ # Casts `unsharp_masking` info option
10
+ module UnsharpMasking
11
+ CASTER = Imgproxy::OptionsCasters::Group.new(
12
+ mode: Imgproxy::OptionsCasters::String,
13
+ weight: Imgproxy::OptionsCasters::Float,
14
+ divider: Imgproxy::OptionsCasters::Float,
15
+ ).freeze
16
+
17
+ def self.cast(raw)
18
+ return raw unless raw.is_a?(Hash)
19
+
20
+ values = CASTER.cast(raw)
21
+ (values[0] == "none") ? "none" : values
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "imgproxy/options_casters/group"
4
+ require "imgproxy/options_casters/float"
5
+ require "imgproxy/options_casters/integer"
6
+ require "imgproxy/options_casters/bool"
7
+
8
+ module Imgproxy
9
+ module OptionsCasters
10
+ # Casts `video_thumbnail_tile` processing option
11
+ module VideoThumbnailTile
12
+ CASTER = Imgproxy::OptionsCasters::Group.new(
13
+ step: Imgproxy::OptionsCasters::Float,
14
+ columns: Imgproxy::OptionsCasters::Integer,
15
+ rows: Imgproxy::OptionsCasters::Integer,
16
+ tile_width: Imgproxy::OptionsCasters::Integer,
17
+ tile_height: Imgproxy::OptionsCasters::Integer,
18
+ extend_tile: Imgproxy::OptionsCasters::Bool,
19
+ trim: Imgproxy::OptionsCasters::Bool,
20
+ ).freeze
21
+
22
+ def self.cast(raw)
23
+ # Allow video_thumbnail_tile to be just a zero
24
+ return 0 if raw.is_a?(Numeric) && raw.zero?
25
+
26
+ return raw unless raw.is_a?(Hash)
27
+ return unless raw[:step]
28
+
29
+ values = CASTER.cast(raw)
30
+ values[0].zero? ? 0 : values
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,17 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "imgproxy/options_casters/group"
2
4
  require "imgproxy/options_casters/float"
3
5
  require "imgproxy/options_casters/string"
4
- require "imgproxy/options_casters/integer"
5
6
 
6
7
  module Imgproxy
7
8
  module OptionsCasters
8
- # Casts string option
9
+ # Casts `watermark` processing option
9
10
  module Watermark
10
11
  CASTER = Imgproxy::OptionsCasters::Group.new(
11
12
  opacity: Imgproxy::OptionsCasters::Float,
12
13
  position: Imgproxy::OptionsCasters::String,
13
- x_offset: Imgproxy::OptionsCasters::Integer,
14
- y_offset: Imgproxy::OptionsCasters::Integer,
14
+ x_offset: Imgproxy::OptionsCasters::Float,
15
+ y_offset: Imgproxy::OptionsCasters::Float,
15
16
  scale: Imgproxy::OptionsCasters::Float,
16
17
  ).freeze
17
18