javaeye3/script/fix_logo.rb

33 lines
778 B
Ruby

require 'rubygems'
require 'mini_magick'
DIR_PATH = "public/upload/logo/space"
module MiniMagick
class Image
def compressing(convert_gif)
format = self[:format]
if convert_gif && format == "GIF"
#convert 1st frame for animation gif
run_command("convert","#{@path}[0]", "#{@path}")
elsif format == "BMP"
format("PNG")
end
end
end
end
Dir["#{DIR_PATH}/**/**"].each{|f|
if File.ftype(f) == "file" && f !~ /-thumb\./
img = MiniMagick::Image.from_file(f)
img.compressing(true)
img.combine_options do |commands|
commands.strip
commands.resize("48x48>")
commands.background("white")
commands.gravity("center")
commands.extent("48x48")
end
img.write(f)
end rescue nil
}