FIX: `FastImage#size` returns `nil` if it can't fetch the image size.
This commit is contained in:
parent
fcc86d3a9d
commit
00078a438b
|
@ -116,13 +116,16 @@ class CookedPostProcessor
|
|||
if w > 0 || h > 0
|
||||
w = w.to_f
|
||||
h = h.to_f
|
||||
original_width, original_height = get_size(img["src"]).map {|integer| integer.to_f}
|
||||
|
||||
return unless original_image_size = get_size(img["src"])
|
||||
original_width, original_height = original_image_size.map(&:to_f)
|
||||
|
||||
if w > 0
|
||||
ratio = w/original_width
|
||||
return [w.floor, (original_height*ratio).floor]
|
||||
[w.floor, (original_height*ratio).floor]
|
||||
else
|
||||
ratio = h/original_height
|
||||
return [(original_width*ratio).floor, h.floor]
|
||||
[(original_width*ratio).floor, h.floor]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -149,7 +152,7 @@ class CookedPostProcessor
|
|||
return unless is_valid_image_url?(absolute_url)
|
||||
|
||||
# we can *always* crawl our own images
|
||||
return unless SiteSetting.crawl_images? || Discourse.store.has_been_uploaded?(url)
|
||||
return unless SiteSetting.crawl_images || Discourse.store.has_been_uploaded?(url)
|
||||
|
||||
@size_cache[url] ||= FastImage.size(absolute_url)
|
||||
rescue Zlib::BufError # FastImage.size raises BufError for some gifs
|
||||
|
|
|
@ -267,6 +267,12 @@ describe CookedPostProcessor do
|
|||
expect(cpp.get_size("http://foo.bar/image2.png")).to eq([100, 200])
|
||||
end
|
||||
|
||||
it "returns nil if FastImage can't get the original size" do
|
||||
Discourse.store.class.any_instance.expects(:has_been_uploaded?).returns(true)
|
||||
FastImage.expects(:size).returns(nil)
|
||||
expect(cpp.get_size("http://foo.bar/image3.png")).to eq(nil)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue