FIX: do not treat TIFF, BMP, WEBP as images

Treating TIFF and BMP as images cause us to add them to IMG tags, this is very inconsistent across browsers.

You can still upload these files they will simply not be displayed in IMG tags.
This commit is contained in:
Penar Musaraj
2019-02-11 00:28:43 -05:00
committed by Sam
parent 84a10f8212
commit c50db76f5d
6 changed files with 18 additions and 23 deletions

View File

@ -3,8 +3,6 @@ require_dependency "image_sizer"
class UploadCreator
TYPES_CONVERTED_TO_JPEG ||= %i{bmp png}
TYPES_TO_CROP ||= %w{avatar card_background custom_emoji profile_background}.each(&:freeze)
WHITELISTED_SVG_ELEMENTS ||= %w{
@ -47,7 +45,7 @@ class UploadCreator
if @image_info.type.to_s == "svg"
whitelist_svg!
elsif !Rails.env.test? || @opts[:force_optimize]
convert_to_jpeg! if should_convert_to_jpeg?
convert_to_jpeg! if convert_png_to_jpeg?
downsize! if should_downsize?
return @upload if is_still_too_big?
@ -158,8 +156,8 @@ class UploadCreator
MIN_PIXELS_TO_CONVERT_TO_JPEG ||= 1280 * 720
def should_convert_to_jpeg?
return false if !TYPES_CONVERTED_TO_JPEG.include?(@image_info.type)
def convert_png_to_jpeg?
return false unless @image_info.type == :png
return true if @opts[:pasted]
return false if SiteSetting.png_to_jpg_quality == 100
pixels > MIN_PIXELS_TO_CONVERT_TO_JPEG