Class: ImageProcessing::Rszr::Processor

Inherits:
Processor
  • Object
show all
Defined in:
lib/rszr/image_processing.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.apply_operation(accumulator, name, args, block) ⇒ Object

Calls the operation to perform the processing. If the operation is defined on the processor (macro), calls it. Otherwise calls the bang variant of the method directly on the Rszr image object.



44
45
46
47
# File 'lib/rszr/image_processing.rb', line 44

def apply_operation(accumulator, (name, args, block))
  return super if method_defined?(name)
  accumulator.send("#{name}!", *args, &block)
end

.load_image(path_or_image, **options) ⇒ Object

Loads the image on disk into a Rszr::Image object



26
27
28
29
30
31
32
33
# File 'lib/rszr/image_processing.rb', line 26

def load_image(path_or_image, **options)
  if path_or_image.is_a?(::Rszr::Image)
    path_or_image
  else
    ::Rszr::Image.load(path_or_image)
  end
  # TODO: image = image.autorot if autorot && !options.key?(:autorotate)
end

.save_image(image, destination_path, **options) ⇒ Object

Writes the image object to disk. Accepts additional options (quality, format).



37
38
39
# File 'lib/rszr/image_processing.rb', line 37

def save_image(image, destination_path, **options)
  image.save(destination_path, **options)
end

Instance Method Details

#resize_to_fill(width, height, gravity: :center, **options) ⇒ Object

Resizes the image to fill the specified dimensions, applying any necessary cropping.



65
66
67
# File 'lib/rszr/image_processing.rb', line 65

def resize_to_fill(width, height, gravity: :center, **options)
  thumbnail(width, height, crop: gravity, **options)
end

#resize_to_fit(width, height, **options) ⇒ Object

Resizes the image to fit within the specified dimensions.



58
59
60
61
# File 'lib/rszr/image_processing.rb', line 58

def resize_to_fit(width, height, **options)
  width, height = default_dimensions(width, height)
  thumbnail(width, height, **options)
end

#resize_to_limit(width, height, **options) ⇒ Object

Resizes the image to not be larger than the specified dimensions.



52
53
54
55
# File 'lib/rszr/image_processing.rb', line 52

def resize_to_limit(width, height, **options)
  width, height = default_dimensions(width, height)
  thumbnail(width, height, inflate: false, **options)
end