posts: fix exception when rendering thumbnails for posts with null width/height.

Fixes https://danbooru.donmai.us/forum_topics/15909?page=4#forum_post_160367.
This commit is contained in:
evazion
2019-10-14 21:16:04 -05:00
parent 18e8b13aeb
commit f6b73a5150

View File

@@ -63,9 +63,15 @@ class PostPresenter < Presenter
locals[:width] = post.image_width
locals[:height] = post.image_height
downscale_ratio = Danbooru.config.small_image_width.to_f / [post.image_width, post.image_height].max
locals[:preview_width] = [(downscale_ratio * post.image_width).floor, post.image_width].min
locals[:preview_height] = [(downscale_ratio * post.image_height).floor, post.image_height].min
# XXX work around ancient bad posts with null or zero dimensions.
if post.image_width.to_i > 0 && post.image_height.to_i > 0
downscale_ratio = Danbooru.config.small_image_width.to_f / [post.image_width, post.image_height].max
locals[:preview_width] = [(downscale_ratio * post.image_width).floor, post.image_width].min
locals[:preview_height] = [(downscale_ratio * post.image_height).floor, post.image_height].min
else
locals[:preview_width] = 0
locals[:preview_height] = 0
end
if options[:similarity]
locals[:similarity] = options[:similarity].round