Class: ImageProcessing::Vips::Processor
- Inherits:
-
Object
- Object
- 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
Instance Method Details
#apply_operation(name, image, *args) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/image_processing/vips.rb', line 23 def apply_operation(name, image, *args) if respond_to?(name) public_send(name, image, *args) else result = image.send(name, *args) result.is_a?(::Vips::Image) ? result : image end end |
#load_image(path_or_image, autorot: true, **options) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/image_processing/vips.rb', line 55 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 loader = ::Vips.vips_foreign_find_load(source_path) = (loader, ) if loader 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
46 47 48 49 50 51 52 53 |
# File 'lib/image_processing/vips.rb', line 46 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 = image.bandjoin(255) if alpha && image.bands == 3 image.gravity(gravity, width, height, **) end |
#resize_to_fill(image, width, height, **options) ⇒ Object
42 43 44 |
# File 'lib/image_processing/vips.rb', line 42 def resize_to_fill(image, width, height, **) image.thumbnail_image(width, height: height, crop: :centre, **) end |
#resize_to_fit(image, width, height, **options) ⇒ Object
37 38 39 40 |
# File 'lib/image_processing/vips.rb', line 37 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
32 33 34 35 |
# File 'lib/image_processing/vips.rb', line 32 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
70 71 72 73 74 75 |
# File 'lib/image_processing/vips.rb', line 70 def save_image(image, destination_path, **) saver = ::Vips.vips_foreign_find_save(destination_path) = (saver, ) if saver image.write_to_file(destination_path, **) end |