#coding=utf-8 module Trustie module Utils class Image def initialize(file, bak) @file = file @bak = bak end def compress(size=300) backup if @bak begin f = Magick::ImageList.new(@file) if f.format != 'GIF' width = size if f[0].columns > width proportion = (width/f[0].columns.to_f) height = (f[0].rows*proportion) f.resize_to_fill!(width,height.to_i) f.write(@file) end end rescue Exception => e Rails.logger.error "[Error] compress : ===> #{e}" end end def backup FileUtils.cp @file, "#{@file}.bak" end end end end