FEATURE: add support for device pixel ratio = 3

This commit is contained in:
Régis Hanol 2015-05-28 01:48:07 +02:00
parent 4f1a72f729
commit e101396ea1
4 changed files with 8 additions and 8 deletions

View File

@ -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) {

View File

@ -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

View File

@ -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

View File

@ -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");