mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:16:38 -06:00
FIX: proper support for pixel ratios up to 3
This commit is contained in:
parent
4215690f40
commit
c3227b69fa
@ -59,7 +59,7 @@ class UserAvatarsController < ApplicationController
|
||||
return render_dot if size < 8 || size > 500
|
||||
|
||||
if !Discourse.avatar_sizes.include?(size) && Discourse.store.external?
|
||||
closest = Discourse.avatar_sizes.to_a.min{|a,b| (size-a).abs <=> (size-b).abs}
|
||||
closest = Discourse.avatar_sizes.to_a.min { |a,b| (size-a).abs <=> (size-b).abs }
|
||||
return redirect_to cdn_path("/user_avatar/#{params[:hostname]}/#{user.username_lower}/#{closest}/#{version}.png")
|
||||
end
|
||||
|
||||
|
@ -17,14 +17,9 @@ module Jobs
|
||||
self.send("create_thumbnails_for_#{type}", upload)
|
||||
end
|
||||
|
||||
PIXEL_RATIOS ||= [1, 2, 3]
|
||||
|
||||
def create_thumbnails_for_avatar(upload)
|
||||
PIXEL_RATIOS.each do |pixel_ratio|
|
||||
Discourse.avatar_sizes.each do |size|
|
||||
size *= pixel_ratio
|
||||
OptimizedImage.create_for(upload, max, max, allow_animation: SiteSetting.allow_animated_avatars)
|
||||
end
|
||||
Discourse.avatar_sizes.each do |size|
|
||||
OptimizedImage.create_for(upload, size, size, allow_animation: SiteSetting.allow_animated_avatars)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -78,11 +78,18 @@ module Discourse
|
||||
@anonymous_top_menu_items ||= Discourse.anonymous_filters + [:category, :categories, :top]
|
||||
end
|
||||
|
||||
PIXEL_RATIOS ||= [1, 2, 3]
|
||||
|
||||
def self.avatar_sizes
|
||||
# Don't cache until we can get a notification from site settings to expire cache
|
||||
set = Set.new(SiteSetting.avatar_sizes.split("|").map(&:to_i))
|
||||
# add retinas which are 2x dpi
|
||||
set.to_a.each { |size| set << size * 2 }
|
||||
# TODO: should cache these when we get a notification system for site settings
|
||||
set = Set.new
|
||||
|
||||
SiteSetting.avatar_sizes.split("|").map(&:to_i).each do |size|
|
||||
PIXEL_RATIOS.each do |pixel_ratio|
|
||||
set << size * pixel_ratio
|
||||
end
|
||||
end
|
||||
|
||||
set
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user