Class: ImageProcessing::Vips::Processor
- Defined in:
- lib/image_processing/vips.rb
Constant Summary collapse
- IMAGE_CLASS =
::Vips::Image
- MAX_COORD =
libvips has this arbitrary number as a sanity-check upper bound on image size.
10_000_000
Instance Method Summary collapse
- #apply_operation(name, image, *args) ⇒ Object
- #load_image(path_or_image, autorot: true, **options) ⇒ Object
- #resize_and_pad(image, width, height, gravity: "centre", extend: nil, background: nil, alpha: nil, **options) ⇒ Object
- #resize_to_fill(image, width, height, **options) ⇒ Object
- #resize_to_fit(image, width, height, **options) ⇒ Object
- #resize_to_limit(image, width, height, **options) ⇒ Object
- #save_image(image, destination_path, **options) ⇒ Object
Methods inherited from Processor
Constructor Details
This class inherits a constructor from ImageProcessing::Processor
Instance Method Details
#apply_operation(name, image, *args) ⇒ Object
23 24 25 26 |
# File 'lib/image_processing/vips.rb', line 23 def apply_operation(name, image, *args) result = super result.is_a?(::Vips::Image) ? result : image end |
#load_image(path_or_image, autorot: true, **options) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/image_processing/vips.rb', line 51 def load_image(path_or_image, autorot: true, **) if path_or_image.is_a?(::Vips::Image) image = path_or_image else source_path = path_or_image = (source_path, ) image = ::Vips::Image.new_from_file(source_path, fail: true, **) end image = image.autorot if autorot image end |
#resize_and_pad(image, width, height, gravity: "centre", extend: nil, background: nil, alpha: nil, **options) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/image_processing/vips.rb', line 42 def resize_and_pad(image, width, height, gravity: "centre", extend: nil, background: nil, alpha: nil, **) = { extend: extend, background: background } .reject! { |name, value| value.nil? } image = image.thumbnail_image(width, height: height, **) image = add_alpha(image) if alpha && !has_alpha?(image) image.gravity(gravity, width, height, **) end |
#resize_to_fill(image, width, height, **options) ⇒ Object
38 39 40 |
# File 'lib/image_processing/vips.rb', line 38 def resize_to_fill(image, width, height, **) image.thumbnail_image(width, height: height, crop: :centre, **) end |
#resize_to_fit(image, width, height, **options) ⇒ Object
33 34 35 36 |
# File 'lib/image_processing/vips.rb', line 33 def resize_to_fit(image, width, height, **) width, height = default_dimensions(width, height) image.thumbnail_image(width, height: height, **) end |
#resize_to_limit(image, width, height, **options) ⇒ Object
28 29 30 31 |
# File 'lib/image_processing/vips.rb', line 28 def resize_to_limit(image, width, height, **) width, height = default_dimensions(width, height) image.thumbnail_image(width, height: height, size: :down, **) end |
#save_image(image, destination_path, **options) ⇒ Object
65 66 67 68 69 |
# File 'lib/image_processing/vips.rb', line 65 def save_image(image, destination_path, **) = (destination_path, ) image.write_to_file(destination_path, **) end |