diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 233f299d11a..262b4f0a902 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -107,13 +107,18 @@ class CookedPostProcessor end def get_size(url) + return @size_cache[url] if @size_cache.has_key?(url) + absolute_url = url absolute_url = Discourse.base_url_no_prefix + absolute_url if absolute_url =~ /^\/[^\/]/ # FastImage fails when there's no scheme absolute_url = SiteSetting.scheme + ":" + absolute_url if absolute_url.start_with?("//") + 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) + @size_cache[url] ||= FastImage.size(absolute_url) rescue Zlib::BufError # FastImage.size raises BufError for some gifs end @@ -131,6 +136,12 @@ class CookedPostProcessor width, height = img["width"].to_i, img["height"].to_i original_width, original_height = get_size(src) + # can't reach the image... + if original_width.nil? || original_height.nil? + Rails.logger.error "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