diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index c1c51717b6b..9af9220dad5 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -29,6 +29,7 @@ class CookedPostProcessor def post_process(bypass_bump = false) DistributedMutex.synchronize("post_process_#{@post.id}") do + DiscourseEvent.trigger(:before_post_process_cooked, @doc, @post) keep_reverse_index_up_to_date post_process_images post_process_oneboxes @@ -193,7 +194,14 @@ class CookedPostProcessor return unless src.present? width, height = img["width"].to_i, img["height"].to_i - original_width, original_height = get_size(src) + upload = Upload.get_from_url(src) + + original_width, original_height = + if upload + [upload.width, upload.height] + else + get_size(src) + end # can't reach the image... if original_width.nil? || @@ -217,7 +225,7 @@ class CookedPostProcessor img["height"] = height end - if upload = Upload.get_from_url(src) + if upload upload.create_thumbnail!(width, height, crop) end diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index e56f364cc66..009a25615c3 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -150,7 +150,7 @@ describe CookedPostProcessor do context "with large images" do - let(:upload) { Fabricate(:upload) } + let(:upload) { Fabricate(:upload, width: 1750, height: 2000) } let(:post) { Fabricate(:post_with_large_image) } let(:cpp) { CookedPostProcessor.new(post) } @@ -179,7 +179,7 @@ describe CookedPostProcessor do context "with large images when using subfolders" do - let(:upload) { Fabricate(:upload) } + let(:upload) { Fabricate(:upload, width: 1750, height: 2000) } let(:post) { Fabricate(:post_with_large_image_on_subfolder) } let(:cpp) { CookedPostProcessor.new(post) } let(:base_url) { "http://test.localhost/subfolder" } @@ -220,7 +220,7 @@ describe CookedPostProcessor do context "with title" do - let(:upload) { Fabricate(:upload) } + let(:upload) { Fabricate(:upload, width: 1750, height: 2000) } let(:post) { Fabricate(:post_with_large_image_and_title) } let(:cpp) { CookedPostProcessor.new(post) }