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) {
|
getRawSize: function(size) {
|
||||||
var pixelRatio = window.devicePixelRatio || 1;
|
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) {
|
avatarImg: function(options) {
|
||||||
|
|
|
@ -17,13 +17,13 @@ module Jobs
|
||||||
self.send("create_thumbnails_for_#{type}", upload)
|
self.send("create_thumbnails_for_#{type}", upload)
|
||||||
end
|
end
|
||||||
|
|
||||||
PIXELS ||= [1, 2]
|
PIXEL_RATIOS ||= [1, 2, 3]
|
||||||
|
|
||||||
def create_thumbnails_for_avatar(upload)
|
def create_thumbnails_for_avatar(upload)
|
||||||
PIXELS.each do |pixel|
|
PIXEL_RATIOS.each do |pixel_ratio|
|
||||||
Discourse.avatar_sizes.each do |size|
|
Discourse.avatar_sizes.each do |size|
|
||||||
size *= pixel
|
size *= pixel_ratio
|
||||||
upload.create_thumbnail!(size, size, SiteSetting.allow_animated_avatars)
|
OptimizedImage.create_for(upload, max, max, allow_animation: SiteSetting.allow_animated_avatars)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,9 +24,9 @@ class Upload < ActiveRecord::Base
|
||||||
thumbnail(width, height).present?
|
thumbnail(width, height).present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_thumbnail!(width, height, allow_animation = SiteSetting.allow_animated_thumbnails)
|
def create_thumbnail!(width, height)
|
||||||
return unless SiteSetting.create_thumbnails?
|
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
|
if thumbnail
|
||||||
optimized_images << thumbnail
|
optimized_images << thumbnail
|
||||||
self.width = width
|
self.width = width
|
||||||
|
|
|
@ -117,7 +117,7 @@ test("isAnImage", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("avatarUrl", function() {
|
test("avatarUrl", function() {
|
||||||
var rawSize = Discourse.Utilities.getRawSize;
|
var rawSize = utils.getRawSize;
|
||||||
blank(utils.avatarUrl('', 'tiny'), "no template returns blank");
|
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', 'tiny'), "/fake/template/" + rawSize(20) + ".png", "simple avatar url");
|
||||||
equal(utils.avatarUrl('/fake/template/{size}.png', 'large'), "/fake/template/" + rawSize(45) + ".png", "different size");
|
equal(utils.avatarUrl('/fake/template/{size}.png', 'large'), "/fake/template/" + rawSize(45) + ".png", "different size");
|
||||||
|
|
Loading…
Reference in New Issue