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
158 159 160 |
# File 'lib/rszr/image.rb', line 158 def blend(*args, **opts) dup.blend!(*args, **opts) end |
#blend!(image, x, y, mode: :copy) ⇒ Object
153 154 155 156 |
# File 'lib/rszr/image.rb', line 153 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
113 114 115 |
# File 'lib/rszr/image.rb', line 113 def blur(radius) dup.blur!(radius) end |
#blur!(radius) ⇒ Object
117 118 119 120 |
# File 'lib/rszr/image.rb', line 117 def blur!(radius) raise ArgumentError, 'illegal radius' if radius < 0 _sharpen!(-radius) end |
#brighten(*args, **opts) ⇒ Object
131 132 133 |
# File 'lib/rszr/image.rb', line 131 def brighten(*args, **opts) dup.brighten!(*args, **opts) end |
#brighten!(value, r: nil, g: nil, b: nil, a: nil) ⇒ Object
126 127 128 129 |
# File 'lib/rszr/image.rb', line 126 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
140 141 142 |
# File 'lib/rszr/image.rb', line 140 def contrast(*args, **opts) dup.contrast!(*args, **opts) end |
#contrast!(value, r: nil, g: nil, b: nil, a: nil) ⇒ Object
135 136 137 138 |
# File 'lib/rszr/image.rb', line 135 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
69 70 71 |
# File 'lib/rszr/image.rb', line 69 def crop(x, y, width, height) _crop(false, x, y, width, height) end |
#crop!(x, y, width, height) ⇒ Object
73 74 75 |
# File 'lib/rszr/image.rb', line 73 def crop!(x, y, width, height) _crop(true, x, y, width, height) end |
#fill(*args, **opts) ⇒ Object
176 177 178 |
# File 'lib/rszr/image.rb', line 176 def fill(*args, **opts) dup.fill(*args, **opts) end |
#fill!(coloring) ⇒ Object
171 172 173 174 |
# File 'lib/rszr/image.rb', line 171 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
122 123 124 |
# File 'lib/rszr/image.rb', line 122 def filter(filter_expr) dup.filter!(filter_expr) end |
#flip ⇒ Object
vertical
100 101 102 |
# File 'lib/rszr/image.rb', line 100 def flip dup.flip! end |
#flop ⇒ Object
horizontal
95 96 97 |
# File 'lib/rszr/image.rb', line 95 def flop dup.flop! end |
#gamma(*args, **opts) ⇒ Object
149 150 151 |
# File 'lib/rszr/image.rb', line 149 def gamma(*args, **opts) dup.gamma!(*args, **opts) end |
#gamma!(value, r: nil, g: nil, b: nil, a: nil) ⇒ Object
144 145 146 147 |
# File 'lib/rszr/image.rb', line 144 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
167 168 169 |
# File 'lib/rszr/image.rb', line 167 def rectangle(*args, **opts) dup.rectangle!(*args, **opts) end |
#rectangle!(coloring, x, y, w, h) ⇒ Object
162 163 164 165 |
# File 'lib/rszr/image.rb', line 162 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
61 62 63 |
# File 'lib/rszr/image.rb', line 61 def resize(*args, **opts) _resize(false, *calculate_size(*args, **opts)) end |
#resize!(*args, **opts) ⇒ Object
65 66 67 |
# File 'lib/rszr/image.rb', line 65 def resize!(*args, **opts) _resize(true, *calculate_size(*args, **opts)) end |
#rotate(deg) ⇒ Object
86 87 88 |
# File 'lib/rszr/image.rb', line 86 def rotate(deg) _rotate(false, deg.to_f * Math::PI / 180.0) end |
#rotate!(deg) ⇒ Object
90 91 92 |
# File 'lib/rszr/image.rb', line 90 def rotate!(deg) _rotate(true, deg.to_f * Math::PI / 180.0) end |
#sharpen(radius) ⇒ Object
104 105 106 |
# File 'lib/rszr/image.rb', line 104 def sharpen(radius) dup.sharpen!(radius) end |
#sharpen!(radius) ⇒ Object
108 109 110 111 |
# File 'lib/rszr/image.rb', line 108 def sharpen!(radius) raise ArgumentError, 'illegal radius' if radius < 0 _sharpen!(radius) end |
#turn(orientation) ⇒ Object
77 78 79 |
# File 'lib/rszr/image.rb', line 77 def turn(orientation) dup.turn!(orientation) end |
#turn!(orientation) ⇒ Object
81 82 83 84 |
# File 'lib/rszr/image.rb', line 81 def turn!(orientation) orientation = orientation.abs + 2 if orientation.negative? _turn!(orientation % 4) end |