Class: ImageProcessing::Vips::Processor
- Defined in:
- lib/image_processing/vips.rb
Constant Summary collapse
- IMAGE_CLASS =
::Vips::Image
- SHARPEN_MASK =
default sharpening mask that provides a fast and mild sharpen
::Vips::Image.new_from_array [[-1, -1, -1], [-1, 32, -1], [-1, -1, -1]], 24
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, quality: nil, **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
24 25 26 27 |
# File 'lib/image_processing/vips.rb', line 24 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
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/image_processing/vips.rb', line 52 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, **) end image = image.autorot if autorot && !.key?(:autorotate) image end |
#resize_and_pad(image, width, height, gravity: "centre", extend: nil, background: nil, alpha: nil, **options) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/image_processing/vips.rb', line 43 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 = thumbnail(image, width, height, **) image = add_alpha(image) if alpha && !has_alpha?(image) image.gravity(gravity, width, height, **) end |
#resize_to_fill(image, width, height, **options) ⇒ Object
39 40 41 |
# File 'lib/image_processing/vips.rb', line 39 def resize_to_fill(image, width, height, **) thumbnail(image, width, height, crop: :centre, **) end |
#resize_to_fit(image, width, height, **options) ⇒ Object
34 35 36 37 |
# File 'lib/image_processing/vips.rb', line 34 def resize_to_fit(image, width, height, **) width, height = default_dimensions(width, height) thumbnail(image, width, height, **) end |
#resize_to_limit(image, width, height, **options) ⇒ Object
29 30 31 32 |
# File 'lib/image_processing/vips.rb', line 29 def resize_to_limit(image, width, height, **) width, height = default_dimensions(width, height) thumbnail(image, width, height, size: :down, **) end |
#save_image(image, destination_path, quality: nil, **options) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/image_processing/vips.rb', line 66 def save_image(image, destination_path, quality: nil, **) = .merge(Q: quality) if quality = (destination_path, ) image.write_to_file(destination_path, **) end |