require 'rmagick'

class Collage

  class Images

    class Cropper

      CROP_WIDTH  = 200
      CROP_HEIGHT = 200

      FLAG_IGNORE_ASPECT_RATIO = "\!".freeze

      def self.run from, to
        image = Magick::Image.read(from).first

        ignore_aspect_ratio_flag = "\!"
        image.change_geometry!("#{CROP_WIDTH}X#{CROP_HEIGHT}#{FLAG_IGNORE_ASPECT_RATIO}") { |cols, rows| image.thumbnail! cols, rows }
        image.write(to) { self.format = "jpeg" }
      end
    end

  end
end
