Module: Rszr::Image::Transformations

Included in:
Rszr::Image
Defined in:
lib/rszr/image.rb

Instance Method Summary collapse

Instance Method Details

#blend(*args, **opts) ⇒ Object



169
170
171
# File 'lib/rszr/image.rb', line 169

def blend(*args, **opts)
  dup.blend!(*args, **opts)
end

#blend!(image, x, y, mode: :copy) ⇒ Object

Raises:

  • (ArgumentError)


164
165
166
167
# File 'lib/rszr/image.rb', line 164

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



114
115
116
# File 'lib/rszr/image.rb', line 114

def blur(radius)
  dup.blur!(radius)
end

#blur!(radius) ⇒ Object

Raises:

  • (ArgumentError)


118
119
120
121
# File 'lib/rszr/image.rb', line 118

def blur!(radius)
  raise ArgumentError, 'illegal radius' if radius < 0
  _sharpen!(-radius)
end

#brighten(*args, **opts) ⇒ Object



142
143
144
# File 'lib/rszr/image.rb', line 142

def brighten(*args, **opts)
  dup.brighten!(*args, **opts)
end

#brighten!(value, r: nil, g: nil, b: nil, a: nil) ⇒ Object

Raises:

  • (ArgumentError)


137
138
139
140
# File 'lib/rszr/image.rb', line 137

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



151
152
153
# File 'lib/rszr/image.rb', line 151

def contrast(*args, **opts)
  dup.contrast!(*args, **opts)
end

#contrast!(value, r: nil, g: nil, b: nil, a: nil) ⇒ Object

Raises:

  • (ArgumentError)


146
147
148
149
# File 'lib/rszr/image.rb', line 146

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



70
71
72
# File 'lib/rszr/image.rb', line 70

def crop(x, y, width, height)
  _crop(false, x, y, width, height)
end

#crop!(x, y, width, height) ⇒ Object



74
75
76
# File 'lib/rszr/image.rb', line 74

def crop!(x, y, width, height)
  _crop(true, x, y, width, height)
end

#desaturate(*args, **opts) ⇒ Object



129
130
131
# File 'lib/rszr/image.rb', line 129

def desaturate(*args, **opts)
  dup.desaturate!(*args, **opts)
end

#desaturate!(mode = :dynamic) ⇒ Object

Raises:

  • (ArgumentError)


123
124
125
126
127
# File 'lib/rszr/image.rb', line 123

def desaturate!(mode = :dynamic)
  _mode = DESATURATION_MODES.index(mode)
  raise ArgumentError, 'illegal mode' unless _mode
  _desaturate!(_mode);
end

#fill(*args, **opts) ⇒ Object



187
188
189
# File 'lib/rszr/image.rb', line 187

def fill(*args, **opts)
  dup.fill(*args, **opts)
end

#fill!(coloring) ⇒ Object

Raises:

  • (ArgumentError)


182
183
184
185
# File 'lib/rszr/image.rb', line 182

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



133
134
135
# File 'lib/rszr/image.rb', line 133

def filter(filter_expr)
  dup.filter!(filter_expr)
end

#flipObject

vertical



101
102
103
# File 'lib/rszr/image.rb', line 101

def flip
  dup.flip!
end

#flopObject

horizontal



96
97
98
# File 'lib/rszr/image.rb', line 96

def flop
  dup.flop!
end

#gamma(*args, **opts) ⇒ Object



160
161
162
# File 'lib/rszr/image.rb', line 160

def gamma(*args, **opts)
  dup.gamma!(*args, **opts)
end

#gamma!(value, r: nil, g: nil, b: nil, a: nil) ⇒ Object



155
156
157
158
# File 'lib/rszr/image.rb', line 155

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



178
179
180
# File 'lib/rszr/image.rb', line 178

def rectangle(*args, **opts)
  dup.rectangle!(*args, **opts)
end

#rectangle!(coloring, x, y, w, h) ⇒ Object

Raises:

  • (ArgumentError)


173
174
175
176
# File 'lib/rszr/image.rb', line 173

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



62
63
64
# File 'lib/rszr/image.rb', line 62

def resize(*args, **opts)
  _resize(false, *calculate_size(*args,  **opts))
end

#resize!(*args, **opts) ⇒ Object



66
67
68
# File 'lib/rszr/image.rb', line 66

def resize!(*args, **opts)
  _resize(true, *calculate_size(*args, **opts))
end

#rotate(deg) ⇒ Object



87
88
89
# File 'lib/rszr/image.rb', line 87

def rotate(deg)
  _rotate(false, deg.to_f * Math::PI / 180.0)
end

#rotate!(deg) ⇒ Object



91
92
93
# File 'lib/rszr/image.rb', line 91

def rotate!(deg)
  _rotate(true, deg.to_f * Math::PI / 180.0)
end

#sharpen(radius) ⇒ Object



105
106
107
# File 'lib/rszr/image.rb', line 105

def sharpen(radius)
  dup.sharpen!(radius)
end

#sharpen!(radius) ⇒ Object

Raises:

  • (ArgumentError)


109
110
111
112
# File 'lib/rszr/image.rb', line 109

def sharpen!(radius)
  raise ArgumentError, 'illegal radius' if radius < 0
  _sharpen!(radius)
end

#turn(orientation) ⇒ Object



78
79
80
# File 'lib/rszr/image.rb', line 78

def turn(orientation)
  dup.turn!(orientation)
end

#turn!(orientation) ⇒ Object



82
83
84
85
# File 'lib/rszr/image.rb', line 82

def turn!(orientation)
  orientation = orientation.abs + 2 if orientation.negative?
  _turn!(orientation % 4)
end