class Attachs::Processors::Image
Public Instance Methods
process(destination_path, geometry)
click to toggle source
# File lib/attachs/processors/image.rb, line 5 def process(destination_path, geometry) if geometry size, suffix = geometry.scan(/([^!#]+)(!|#)?$/).flatten strategy = detect_strategy(suffix) new_width, new_height = size.split('x').map(&:to_i) resize new_width, new_height, strategy, destination_path else Console.convert source_path, destination_path end end
Private Instance Methods
detect_strategy(suffix)
click to toggle source
# File lib/attachs/processors/image.rb, line 18 def detect_strategy(suffix) case suffix when '#' :cover when '!' :force else :contain end end
resize(new_width, new_height, strategy, destination_path)
click to toggle source
# File lib/attachs/processors/image.rb, line 29 def resize(new_width, new_height, strategy, destination_path) options = [Attachs.configuration.convert_options] case strategy when :cover options << "-resize #{new_width}x#{new_height}^ -gravity center" options << "-crop #{new_width}x#{new_height}+0+0 +repage" when :force options << "-resize #{new_width}x#{new_height}\!" when :contain options << "-resize #{new_width}x#{new_height}" end Console.convert source_path, destination_path, options.join(' ') end