保持上传头像比例

exceptionHandle
wanglinchun 12 years ago
parent 0d44c2314c
commit ae7949e8cc

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

Loading…
Cancel
Save