mirror of
https://github.com/discourse/discourse.git
synced 2025-03-06 03:09:43 +00:00
FIX stretched thumbnails
This commit is contained in:
parent
549060867d
commit
6b6c3d05dd
@ -70,11 +70,22 @@ class CookedPostProcessor
|
|||||||
end
|
end
|
||||||
|
|
||||||
def limit_size!(img)
|
def limit_size!(img)
|
||||||
w, h = get_size_from_image_sizes(img["src"], @opts[:image_sizes]) || get_size(img["src"])
|
# retrieve the size from
|
||||||
|
# 1) the width/height attributes
|
||||||
|
# 2) the dimension from the preview (image_sizes)
|
||||||
|
# 3) the dimension of the original image (HTTP request)
|
||||||
|
w, h = get_size_from_attributes(img) ||
|
||||||
|
get_size_from_image_sizes(img["src"], @opts[:image_sizes]) ||
|
||||||
|
get_size(img["src"])
|
||||||
# limit the size of the thumbnail
|
# limit the size of the thumbnail
|
||||||
img["width"], img["height"] = ImageSizer.resize(w, h)
|
img["width"], img["height"] = ImageSizer.resize(w, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_size_from_attributes(img)
|
||||||
|
w, h = img["width"].to_i, img["height"].to_i
|
||||||
|
return [w, h] if w > 0 && h > 0
|
||||||
|
end
|
||||||
|
|
||||||
def get_size_from_image_sizes(src, image_sizes)
|
def get_size_from_image_sizes(src, image_sizes)
|
||||||
return unless image_sizes.present?
|
return unless image_sizes.present?
|
||||||
image_sizes.each do |image_size|
|
image_sizes.each do |image_size|
|
||||||
|
@ -42,12 +42,20 @@ describe CookedPostProcessor do
|
|||||||
|
|
||||||
context "with image_sizes" do
|
context "with image_sizes" do
|
||||||
|
|
||||||
let(:post) { build(:post_with_image_url) }
|
let(:post) { build(:post_with_image_urls) }
|
||||||
let(:cpp) { CookedPostProcessor.new(post, image_sizes: {"http://foo.bar/image.png" => {"width" => 111, "height" => 222}}) }
|
let(:cpp) { CookedPostProcessor.new(post, image_sizes: {"http://foo.bar/image.png" => {"width" => 111, "height" => 222}}) }
|
||||||
|
|
||||||
|
before { cpp.post_process_images }
|
||||||
|
|
||||||
|
it "adds the width from the image sizes provided when no dimension is provided" do
|
||||||
|
cpp.html.should =~ /src="http:\/\/foo.bar\/image.png" width="111" height="222"/
|
||||||
|
end
|
||||||
|
|
||||||
it "adds the width from the image sizes provided" do
|
it "adds the width from the image sizes provided" do
|
||||||
cpp.post_process_images
|
cpp.html.should =~ /src="http:\/\/domain.com\/picture.jpg" width="50" height="42"/
|
||||||
cpp.html.should =~ /width=\"111\"/
|
end
|
||||||
|
|
||||||
|
it "should be dirty" do
|
||||||
cpp.should be_dirty
|
cpp.should be_dirty
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -58,8 +58,11 @@ Fabricator(:post_with_unsized_images, from: :post) do
|
|||||||
'
|
'
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:post_with_image_url, from: :post) do
|
Fabricator(:post_with_image_urls, from: :post) do
|
||||||
cooked '<img src="http://foo.bar/image.png" width="50" height="42">'
|
cooked '
|
||||||
|
<img src="http://foo.bar/image.png">
|
||||||
|
<img src="http://domain.com/picture.jpg" width="50" height="42">
|
||||||
|
'
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:post_with_large_image, from: :post) do
|
Fabricator(:post_with_large_image, from: :post) do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user