mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 07:38:01 +08:00
FEATURE: add support for device pixel ratio = 3
This commit is contained in:
parent
4f1a72f729
commit
e101396ea1
|
@ -32,7 +32,7 @@ Discourse.Utilities = {
|
|||
|
||||
getRawSize: function(size) {
|
||||
var pixelRatio = window.devicePixelRatio || 1;
|
||||
return pixelRatio >= 1.5 ? size * 2 : size;
|
||||
return size * Math.min(3, Math.max(1, Math.round(pixelRatio)));
|
||||
},
|
||||
|
||||
avatarImg: function(options) {
|
||||
|
|
|
@ -17,13 +17,13 @@ module Jobs
|
|||
self.send("create_thumbnails_for_#{type}", upload)
|
||||
end
|
||||
|
||||
PIXELS ||= [1, 2]
|
||||
PIXEL_RATIOS ||= [1, 2, 3]
|
||||
|
||||
def create_thumbnails_for_avatar(upload)
|
||||
PIXELS.each do |pixel|
|
||||
PIXEL_RATIOS.each do |pixel_ratio|
|
||||
Discourse.avatar_sizes.each do |size|
|
||||
size *= pixel
|
||||
upload.create_thumbnail!(size, size, SiteSetting.allow_animated_avatars)
|
||||
size *= pixel_ratio
|
||||
OptimizedImage.create_for(upload, max, max, allow_animation: SiteSetting.allow_animated_avatars)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,9 +24,9 @@ class Upload < ActiveRecord::Base
|
|||
thumbnail(width, height).present?
|
||||
end
|
||||
|
||||
def create_thumbnail!(width, height, allow_animation = SiteSetting.allow_animated_thumbnails)
|
||||
def create_thumbnail!(width, height)
|
||||
return unless SiteSetting.create_thumbnails?
|
||||
thumbnail = OptimizedImage.create_for(self, width, height, allow_animation: allow_animation)
|
||||
thumbnail = OptimizedImage.create_for(self, width, height, allow_animation: SiteSetting.allow_animated_thumbnails)
|
||||
if thumbnail
|
||||
optimized_images << thumbnail
|
||||
self.width = width
|
||||
|
|
|
@ -117,7 +117,7 @@ test("isAnImage", function() {
|
|||
});
|
||||
|
||||
test("avatarUrl", function() {
|
||||
var rawSize = Discourse.Utilities.getRawSize;
|
||||
var rawSize = utils.getRawSize;
|
||||
blank(utils.avatarUrl('', 'tiny'), "no template returns blank");
|
||||
equal(utils.avatarUrl('/fake/template/{size}.png', 'tiny'), "/fake/template/" + rawSize(20) + ".png", "simple avatar url");
|
||||
equal(utils.avatarUrl('/fake/template/{size}.png', 'large'), "/fake/template/" + rawSize(45) + ".png", "different size");
|
||||
|
|
Loading…
Reference in New Issue
Block a user