FIX: images aren't lightboxed anymore (partially reverts 646c6eb7cd
)
This commit is contained in:
parent
c838f43a75
commit
cbdfc85466
|
@ -183,7 +183,7 @@ class CookedPostProcessor
|
|||
# we can *always* crawl our own images
|
||||
return unless SiteSetting.crawl_images? || Discourse.store.has_been_uploaded?(url)
|
||||
|
||||
@size_cache[url] ||= FastImage.size(absolute_url)
|
||||
@size_cache[url] = FastImage.size(absolute_url)
|
||||
rescue Zlib::BufError # FastImage.size raises BufError for some gifs
|
||||
end
|
||||
|
||||
|
@ -199,30 +199,21 @@ class CookedPostProcessor
|
|||
|
||||
def convert_to_link!(img)
|
||||
src = img["src"]
|
||||
return unless src.present?
|
||||
return if src.blank?
|
||||
|
||||
width, height = img["width"].to_i, img["height"].to_i
|
||||
upload = Upload.get_from_url(src)
|
||||
|
||||
original_width, original_height =
|
||||
if upload
|
||||
[upload.width, upload.height]
|
||||
else
|
||||
get_size(src)
|
||||
end
|
||||
# TODO: even though get_size is cached, a better solution is to store
|
||||
# both original and "cropped" dimensions on the uploads table
|
||||
original_width, original_height = (get_size(src) || [0, 0]).map(&:to_i)
|
||||
|
||||
# can't reach the image...
|
||||
if original_width.nil? ||
|
||||
original_height.nil? ||
|
||||
original_width == 0 ||
|
||||
original_height == 0
|
||||
if original_width == 0 || original_height == 0
|
||||
Rails.logger.info "Can't reach '#{src}' to get its dimension."
|
||||
return
|
||||
end
|
||||
|
||||
return if original_width.to_i <= width && original_height.to_i <= height
|
||||
return if original_width.to_i <= SiteSetting.max_image_width && original_height.to_i <= SiteSetting.max_image_height
|
||||
|
||||
return if original_width <= width && original_height <= height
|
||||
return if original_width <= SiteSetting.max_image_width && original_height <= SiteSetting.max_image_height
|
||||
return if is_a_hyperlink?(img)
|
||||
|
||||
crop = false
|
||||
|
@ -233,7 +224,7 @@ class CookedPostProcessor
|
|||
img["height"] = height
|
||||
end
|
||||
|
||||
if upload
|
||||
if upload = Upload.get_from_url(src)
|
||||
upload.create_thumbnail!(width, height, crop)
|
||||
end
|
||||
|
||||
|
|
|
@ -90,9 +90,7 @@ describe CookedPostProcessor do
|
|||
|
||||
shared_examples "leave dimensions alone" do
|
||||
it "doesn't use them" do
|
||||
# adds the width from the image sizes provided when no dimension is provided
|
||||
expect(cpp.html).to match(/src="http:\/\/foo.bar\/image.png" width="" height=""/)
|
||||
# adds the width from the image sizes provided
|
||||
expect(cpp.html).to match(/src="http:\/\/domain.com\/picture.jpg" width="50" height="42"/)
|
||||
expect(cpp).to be_dirty
|
||||
end
|
||||
|
@ -108,10 +106,7 @@ describe CookedPostProcessor do
|
|||
let(:image_sizes) { { "http://foo.bar/image.png" => { "width" => 111, "height" => 222 } } }
|
||||
|
||||
it "uses them" do
|
||||
|
||||
# adds the width from the image sizes provided when no dimension is provided
|
||||
expect(cpp.html).to match(/src="http:\/\/foo.bar\/image.png" width="111" height="222"/)
|
||||
# adds the width from the image sizes provided
|
||||
expect(cpp.html).to match(/src="http:\/\/domain.com\/picture.jpg" width="50" height="42"/)
|
||||
expect(cpp).to be_dirty
|
||||
end
|
||||
|
@ -150,7 +145,7 @@ describe CookedPostProcessor do
|
|||
|
||||
context "with large images" do
|
||||
|
||||
let(:upload) { Fabricate(:upload, width: 1750, height: 2000) }
|
||||
let(:upload) { Fabricate(:upload) }
|
||||
let(:post) { Fabricate(:post_with_large_image) }
|
||||
let(:cpp) { CookedPostProcessor.new(post) }
|
||||
|
||||
|
@ -159,9 +154,7 @@ describe CookedPostProcessor do
|
|||
SiteSetting.create_thumbnails = true
|
||||
|
||||
Upload.expects(:get_from_url).returns(upload)
|
||||
FastImage.stubs(:size).returns([1750, 2000])
|
||||
|
||||
# hmmm this should be done in a cleaner way
|
||||
FastImage.expects(:size).returns([1750, 2000])
|
||||
OptimizedImage.expects(:resize).returns(true)
|
||||
|
||||
FileStore::BaseStore.any_instance.expects(:get_depth_for).returns(0)
|
||||
|
@ -179,7 +172,7 @@ describe CookedPostProcessor do
|
|||
|
||||
context "with large images when using subfolders" do
|
||||
|
||||
let(:upload) { Fabricate(:upload, width: 1750, height: 2000) }
|
||||
let(:upload) { Fabricate(:upload) }
|
||||
let(:post) { Fabricate(:post_with_large_image_on_subfolder) }
|
||||
let(:cpp) { CookedPostProcessor.new(post) }
|
||||
let(:base_url) { "http://test.localhost/subfolder" }
|
||||
|
@ -192,9 +185,7 @@ describe CookedPostProcessor do
|
|||
Discourse.stubs(:base_uri).returns(base_uri)
|
||||
|
||||
Upload.expects(:get_from_url).returns(upload)
|
||||
FastImage.stubs(:size).returns([1750, 2000])
|
||||
|
||||
# hmmm this should be done in a cleaner way
|
||||
FastImage.expects(:size).returns([1750, 2000])
|
||||
OptimizedImage.expects(:resize).returns(true)
|
||||
|
||||
FileStore::BaseStore.any_instance.expects(:get_depth_for).returns(0)
|
||||
|
@ -220,7 +211,7 @@ describe CookedPostProcessor do
|
|||
|
||||
context "with title" do
|
||||
|
||||
let(:upload) { Fabricate(:upload, width: 1750, height: 2000) }
|
||||
let(:upload) { Fabricate(:upload) }
|
||||
let(:post) { Fabricate(:post_with_large_image_and_title) }
|
||||
let(:cpp) { CookedPostProcessor.new(post) }
|
||||
|
||||
|
@ -229,10 +220,9 @@ describe CookedPostProcessor do
|
|||
SiteSetting.create_thumbnails = true
|
||||
|
||||
Upload.expects(:get_from_url).returns(upload)
|
||||
FastImage.stubs(:size).returns([1750, 2000])
|
||||
|
||||
# hmmm this should be done in a cleaner way
|
||||
FastImage.expects(:size).returns([1750, 2000])
|
||||
OptimizedImage.expects(:resize).returns(true)
|
||||
|
||||
FileStore::BaseStore.any_instance.expects(:get_depth_for).returns(0)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue