Sha256: b1ba869e89ae566bb4ce03c3cb17376253c8803bb11f0b7985a54d9b21818614
Contents?: true
Size: 1.21 KB
Versions: 6
Compression:
Stored size: 1.21 KB
Contents
module Attachs module Processors class Image < Base 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 def detect_strategy(suffix) case suffix when '#' :cover when '!' :force else :contain end end 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 end end end
Version data entries
6 entries across 6 versions & 1 rubygems