保持上传头像比例

This commit is contained in:
wanglinchun 2014-01-20 08:18:57 +08:00
parent 0d44c2314c
commit ae7949e8cc
1 changed files with 15 additions and 13 deletions

View File

@ -49,19 +49,21 @@ class AvatarController < ApplicationController
# self.digest = md5.hexdigest
end
@temp_file = nil
# @avatar = Avatar.new(:receive_file => request.raw_post)
# @avatar.source_id = User.current.id
# @avatar.image_file = params[:filename].presence || Redmine::Utils.random_hex(16)
# saved = @avatar.save
begin
f = Magick::ImageList.new(diskfile)
proportion = (200.0/f[0].columns)
f.resize_to_fill!(200,200)
#f.scale!(50,50)
f.write(diskfile)
rescue Exception => e
logger.error "[Error] avatar : avatar_controller#upload ===> #{e}"
end
# @avatar = Avatar.new(:receive_file => request.raw_post)
# @avatar.source_id = User.current.id
# @avatar.image_file = params[:filename].presence || Redmine::Utils.random_hex(16)
# saved = @avatar.save
begin
f = Magick::ImageList.new(diskfile)
width = 300.0;
proportion = (width/f[0].columns)
height = (f[0].rows*proportion)
f.resize_to_fill!(width,height)
# f.scale!(width,height)
f.write(diskfile)
rescue Exception => e
logger.error "[Error] avatar : avatar_controller#upload ===> #{e}"
end
respond_to do |format|