Class: Vips::Thumbnail::Resizer
- Inherits:
-
Object
- Object
- Vips::Thumbnail::Resizer
- Defined in:
- lib/vips/thumbnail/resizer.rb
Instance Attribute Summary collapse
-
#input_path ⇒ Object
readonly
Returns the value of attribute input_path.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #flush! ⇒ Object
-
#initialize(input_path, **options) ⇒ Resizer
constructor
A new instance of Resizer.
- #input_aspect_ratio ⇒ Object
- #input_image ⇒ Object
-
#resize_to_fill(output_size) ⇒ Vips::Image
Resize the image to completely fill the desired size, if possible.
-
#resize_to_fit(output_size) ⇒ Vips::Image
Resize the image to fit within the given bounds, preserving aspect ratio.
Constructor Details
#initialize(input_path, **options) ⇒ Resizer
Returns a new instance of Resizer.
26 27 28 29 30 |
# File 'lib/vips/thumbnail/resizer.rb', line 26 def initialize(input_path, **) @input_path = input_path @options = @input_image = nil end |
Instance Attribute Details
#input_path ⇒ Object (readonly)
Returns the value of attribute input_path.
32 33 34 |
# File 'lib/vips/thumbnail/resizer.rb', line 32 def input_path @input_path end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
33 34 35 |
# File 'lib/vips/thumbnail/resizer.rb', line 33 def @options end |
Instance Method Details
#flush! ⇒ Object
35 36 37 |
# File 'lib/vips/thumbnail/resizer.rb', line 35 def flush! @input_image = nil end |
#input_aspect_ratio ⇒ Object
48 49 50 |
# File 'lib/vips/thumbnail/resizer.rb', line 48 def input_aspect_ratio Rational(input_image.width, input_image.height) end |
#input_image ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/vips/thumbnail/resizer.rb', line 39 def input_image unless @input_image image = Vips::Image.new_from_file(@input_path, **@options) @input_image = image.autorot end return @input_image end |
#resize_to_fill(output_size) ⇒ Vips::Image
Resize the image to completely fill the desired size, if possible.
54 55 56 57 58 59 60 61 |
# File 'lib/vips/thumbnail/resizer.rb', line 54 def resize_to_fill(output_size) width, height = *output_size # We can only fill and crop if the input image is BIGGER in at least one dimension than the desired output size: if input_image.width > width or input_image.height > height return fill_and_crop(input_image, width, height) end end |
#resize_to_fit(output_size) ⇒ Vips::Image
Resize the image to fit within the given bounds, preserving aspect ratio.
65 66 67 68 69 70 71 72 |
# File 'lib/vips/thumbnail/resizer.rb', line 65 def resize_to_fit(output_size) width, height = *output_size # We can only fit if the input image is BIGGER in at least one dimension than the desired output size: if input_image.width > width or input_image.height > height return fit(input_image, width, height) end end |