Class: Riiif::VipsResize
- Inherits:
-
Object
- Object
- Riiif::VipsResize
- Defined in:
- app/services/riiif/vips_resize.rb
Overview
Represents a resize operation
Instance Attribute Summary collapse
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
-
#initialize(size, image) ⇒ VipsResize
constructor
A new instance of VipsResize.
-
#resize_ratio(side, image) ⇒ Float
-
the scale or percentage to resize the image by; passed to Vips::Image#resize.
-
-
#to_vips ⇒ Object
The parameters that vips will use to resize the image.
Constructor Details
#initialize(size, image) ⇒ VipsResize
Returns a new instance of VipsResize.
4 5 6 7 |
# File 'app/services/riiif/vips_resize.rb', line 4 def initialize(size, image) @size = size @image = image end |
Instance Attribute Details
#image ⇒ Object (readonly)
Returns the value of attribute image.
9 10 11 |
# File 'app/services/riiif/vips_resize.rb', line 9 def image @image end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
9 10 11 |
# File 'app/services/riiif/vips_resize.rb', line 9 def size @size end |
Instance Method Details
#resize_ratio(side, image) ⇒ Float
Returns - the scale or percentage to resize the image by; passed to Vips::Image#resize.
37 38 39 40 41 42 43 44 45 |
# File 'app/services/riiif/vips_resize.rb', line 37 def resize_ratio(side, image) length = image.send(side) target_length = size.send(side) if target_length < length target_length / length.to_f # Size down else length / target_length.to_f # Size up end end |
#to_vips ⇒ Object
Returns the parameters that vips will use to resize the image. This can be
-
A [Float] representing the scale factor, passed to Vips::Image#resize
-
An [Array], where the 1st elem is an Integer and the 2nd is a
Hash of options, passed to Vips::Image#thumbnail - NilClass
-
when image should not be resized at all.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/services/riiif/vips_resize.rb', line 16 def to_vips case size when IIIF::Image::Size::Percent size.percentage when IIIF::Image::Size::Width resize_ratio(:width, image) when IIIF::Image::Size::Height resize_ratio(:height, image) when IIIF::Image::Size::Absolute [size.width, { height: size.height, size: :force }] when IIIF::Image::Size::BestFit [size.width, { height: size.height }] when IIIF::Image::Size::Max, IIIF::Image::Size::Full nil else raise "unknown size #{size.class}" end end |