Module: Rszr::Image::Transformations
- Included in:
- Rszr::Image
- Defined in:
- lib/rszr/image.rb
Instance Method Summary collapse
- #blend(*args, **opts) ⇒ Object
- #blend!(image, x, y, mode: :copy) ⇒ Object
- #blur(radius) ⇒ Object
- #blur!(radius) ⇒ Object
- #brighten(*args, **opts) ⇒ Object
- #brighten!(value, r: nil, g: nil, b: nil, a: nil) ⇒ Object
- #contrast(*args, **opts) ⇒ Object
- #contrast!(value, r: nil, g: nil, b: nil, a: nil) ⇒ Object
- #crop(x, y, width, height) ⇒ Object
- #crop!(x, y, width, height) ⇒ Object
- #fill(*args, **opts) ⇒ Object
- #fill!(coloring) ⇒ Object
- #filter(filter_expr) ⇒ Object
-
#flip ⇒ Object
vertical.
-
#flop ⇒ Object
horizontal.
- #gamma(*args, **opts) ⇒ Object
- #gamma!(value, r: nil, g: nil, b: nil, a: nil) ⇒ Object
- #rectangle(*args, **opts) ⇒ Object
- #rectangle!(coloring, x, y, w, h) ⇒ Object
- #resize(*args, **opts) ⇒ Object
- #resize!(*args, **opts) ⇒ Object
- #rotate(deg) ⇒ Object
- #rotate!(deg) ⇒ Object
- #sharpen(radius) ⇒ Object
- #sharpen!(radius) ⇒ Object
- #turn(orientation) ⇒ Object
- #turn!(orientation) ⇒ Object
Instance Method Details
#blend(*args, **opts) ⇒ Object
156 157 158 |
# File 'lib/rszr/image.rb', line 156 def blend(*args, **opts) dup.blend!(*args, **opts) end |
#blend!(image, x, y, mode: :copy) ⇒ Object
151 152 153 154 |
# File 'lib/rszr/image.rb', line 151 def blend!(image, x, y, mode: :copy) raise ArgumentError, "mode must be one of #{BLENDING_MODES.map(&:to_s).join(', ')}" unless BLENDING_MODES.include?(mode) _blend(image, true, BLENDING_MODES.index(mode), 0, 0, image.width, image.height, x, y, image.width, image.height) end |
#blur(radius) ⇒ Object
111 112 113 |
# File 'lib/rszr/image.rb', line 111 def blur(radius) dup.blur!(radius) end |
#blur!(radius) ⇒ Object
115 116 117 118 |
# File 'lib/rszr/image.rb', line 115 def blur!(radius) raise ArgumentError, 'illegal radius' if radius < 0 _sharpen!(-radius) end |
#brighten(*args, **opts) ⇒ Object
129 130 131 |
# File 'lib/rszr/image.rb', line 129 def brighten(*args, **opts) dup.brighten!(*args, **opts) end |
#brighten!(value, r: nil, g: nil, b: nil, a: nil) ⇒ Object
124 125 126 127 |
# File 'lib/rszr/image.rb', line 124 def brighten!(value, r: nil, g: nil, b: nil, a: nil) raise ArgumentError, 'illegal brightness' if value > 1 || value < -1 filter!("colormod(brightness=#{value.to_f});") end |
#contrast(*args, **opts) ⇒ Object
138 139 140 |
# File 'lib/rszr/image.rb', line 138 def contrast(*args, **opts) dup.contrast!(*args, **opts) end |
#contrast!(value, r: nil, g: nil, b: nil, a: nil) ⇒ Object
133 134 135 136 |
# File 'lib/rszr/image.rb', line 133 def contrast!(value, r: nil, g: nil, b: nil, a: nil) raise ArgumentError, 'illegal contrast (must be > 0)' if value < 0 filter!("colormod(contrast=#{value.to_f});") end |
#crop(x, y, width, height) ⇒ Object
67 68 69 |
# File 'lib/rszr/image.rb', line 67 def crop(x, y, width, height) _crop(false, x, y, width, height) end |
#crop!(x, y, width, height) ⇒ Object
71 72 73 |
# File 'lib/rszr/image.rb', line 71 def crop!(x, y, width, height) _crop(true, x, y, width, height) end |
#fill(*args, **opts) ⇒ Object
174 175 176 |
# File 'lib/rszr/image.rb', line 174 def fill(*args, **opts) dup.fill(*args, **opts) end |
#fill!(coloring) ⇒ Object
169 170 171 172 |
# File 'lib/rszr/image.rb', line 169 def fill!(coloring) raise ArgumentError, "coloring must respond to to_fill" unless coloring.respond_to?(:to_fill) rectangle!(coloring, 0, 0, width, height) end |
#filter(filter_expr) ⇒ Object
120 121 122 |
# File 'lib/rszr/image.rb', line 120 def filter(filter_expr) dup.filter!(filter_expr) end |
#flip ⇒ Object
vertical
98 99 100 |
# File 'lib/rszr/image.rb', line 98 def flip dup.flip! end |
#flop ⇒ Object
horizontal
93 94 95 |
# File 'lib/rszr/image.rb', line 93 def flop dup.flop! end |
#gamma(*args, **opts) ⇒ Object
147 148 149 |
# File 'lib/rszr/image.rb', line 147 def gamma(*args, **opts) dup.gamma!(*args, **opts) end |
#gamma!(value, r: nil, g: nil, b: nil, a: nil) ⇒ Object
142 143 144 145 |
# File 'lib/rszr/image.rb', line 142 def gamma!(value, r: nil, g: nil, b: nil, a: nil) #raise ArgumentError, 'illegal gamma (must be > 0)' if value < 0 filter!("colormod(gamma=#{value.to_f});") end |
#rectangle(*args, **opts) ⇒ Object
165 166 167 |
# File 'lib/rszr/image.rb', line 165 def rectangle(*args, **opts) dup.rectangle!(*args, **opts) end |
#rectangle!(coloring, x, y, w, h) ⇒ Object
160 161 162 163 |
# File 'lib/rszr/image.rb', line 160 def rectangle!(coloring, x, y, w, h) raise ArgumentError, "coloring must respond to to_fill" unless coloring.respond_to?(:to_fill) _rectangle!(coloring.to_fill, x, y, w, h) end |
#resize(*args, **opts) ⇒ Object
59 60 61 |
# File 'lib/rszr/image.rb', line 59 def resize(*args, **opts) _resize(false, *calculate_size(*args, **opts)) end |
#resize!(*args, **opts) ⇒ Object
63 64 65 |
# File 'lib/rszr/image.rb', line 63 def resize!(*args, **opts) _resize(true, *calculate_size(*args, **opts)) end |
#rotate(deg) ⇒ Object
84 85 86 |
# File 'lib/rszr/image.rb', line 84 def rotate(deg) _rotate(false, deg.to_f * Math::PI / 180.0) end |
#rotate!(deg) ⇒ Object
88 89 90 |
# File 'lib/rszr/image.rb', line 88 def rotate!(deg) _rotate(true, deg.to_f * Math::PI / 180.0) end |
#sharpen(radius) ⇒ Object
102 103 104 |
# File 'lib/rszr/image.rb', line 102 def sharpen(radius) dup.sharpen!(radius) end |
#sharpen!(radius) ⇒ Object
106 107 108 109 |
# File 'lib/rszr/image.rb', line 106 def sharpen!(radius) raise ArgumentError, 'illegal radius' if radius < 0 _sharpen!(radius) end |
#turn(orientation) ⇒ Object
75 76 77 |
# File 'lib/rszr/image.rb', line 75 def turn(orientation) dup.turn!(orientation) end |
#turn!(orientation) ⇒ Object
79 80 81 82 |
# File 'lib/rszr/image.rb', line 79 def turn!(orientation) orientation = orientation.abs + 2 if orientation.negative? _turn!(orientation % 4) end |