From 2affd4a3b5a50cfb723ab27b84c22dd8412a7557 Mon Sep 17 00:00:00 2001 From: BrokenEagle Date: Fri, 14 Feb 2020 20:46:57 +0000 Subject: [PATCH] Fix post resize image control It was resizing images to the original width and height, even if they were currently being shown in their large image format (850px). This was causing excessive blur and artifacts in some cases. --- app/javascript/src/javascripts/posts.js.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/javascript/src/javascripts/posts.js.erb b/app/javascript/src/javascripts/posts.js.erb index d678c5706..9b4549713 100644 --- a/app/javascript/src/javascripts/posts.js.erb +++ b/app/javascript/src/javascripts/posts.js.erb @@ -361,6 +361,9 @@ Post.resize_image_to_window = function($img) { var sidebar_width = 0; var client_width = 0; + var isVideo = $img.prop("tagName") === "VIDEO"; + var width = isVideo ? $img.prop("width") : $img.prop('naturalWidth'); + var height = isVideo ? $img.prop("height") : $img.prop('naturalHeight'); if (($img.data("scale-factor") === 1) || ($img.data("scale-factor") === undefined)) { if ($(window).width() > 660) { sidebar_width = $("#sidebar").width() || 0; @@ -370,9 +373,6 @@ Post.resize_image_to_window = function($img) { } if ($img.width() > client_width) { - var isVideo = $img.prop("tagName") === "VIDEO"; - var width = isVideo ? $img.prop("width") : $img.data("original-width"); - var height = isVideo ? $img.prop("height") : $img.data("original-height"); var ratio = client_width / width; $img.data("scale-factor", ratio); $img.css("width", width * ratio); @@ -381,8 +381,8 @@ Post.resize_image_to_window = function($img) { } } else { $img.data("scale-factor", 1); - $img.width($img.data("original-width")); - $img.height($img.data("original-height")); + $img.width(width); + $img.height(height); Post.resize_ugoira_controls(); }