FEATURE: consider SVG as an image when authorized

This commit is contained in:
Régis Hanol
2014-11-03 19:54:10 +01:00
parent bab4f48eeb
commit bdb78ce76a
5 changed files with 58 additions and 12 deletions

View File

@@ -31,9 +31,16 @@ class OptimizedImage < ActiveRecord::Base
extension = File.extname(original_path)
temp_file = Tempfile.new(["discourse-thumbnail", extension])
temp_path = temp_file.path
original_path += "[0]" unless opts[:allow_animation]
if resize(original_path, temp_path, width, height)
if extension =~ /\.svg$/i
FileUtils.cp(original_path, temp_path)
resized = true
else
original_path << "[0]" unless opts[:allow_animation]
resized = resize(original_path, temp_path, width, height)
end
if resized
thumbnail = OptimizedImage.create!(
upload_id: upload.id,
sha1: Digest::SHA1.file(temp_path).hexdigest,