parent
3f88a67eef
commit
eed39ef0ef
@ -1,4 +1,4 @@
|
||||
var imgSpan = $('#avatar_image');
|
||||
|
||||
imgSpan.attr({"src":'<%= @urlfile.to_s << "?" << Time.now.to_s%>'});
|
||||
imgSpan.attr({"src":'<%= "#{@urlfile.to_s}?#{Time.now.to_i}" %>'});
|
||||
|
||||
|
@ -0,0 +1,11 @@
|
||||
desc "compress and backup avatar"
|
||||
task :compress_avatar => :environment do
|
||||
path = File.join(Rails.root, "public/images/avatars/User")
|
||||
Dir.foreach(path) do |f|
|
||||
if f.to_s =~ /^\d+$/
|
||||
puts f
|
||||
image = Trustie::Utils::Image.new(File.join(path,f), true)
|
||||
image.compress(300)
|
||||
end
|
||||
end
|
||||
end
|
@ -1 +1,2 @@
|
||||
require 'trustie/utils'
|
||||
require 'trustie/utils'
|
||||
require 'trustie/utils/image'
|
||||
|
@ -0,0 +1,35 @@
|
||||
#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
|
||||
logger.error "[Error] compress : ===> #{e}"
|
||||
end
|
||||
end
|
||||
|
||||
def backup
|
||||
FileUtils.cp @file, "#{@file}.bak"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in new issue