Support varying ICO files

Closes #32096.
This commit is contained in:
George Claghorn 2018-02-24 15:27:53 -05:00
parent d04b5179ff
commit 3915a470d2
4 changed files with 21 additions and 2 deletions

View File

@ -115,7 +115,7 @@ class ActiveStorage::Variant
def download_image
require "mini_magick"
MiniMagick::Image.create { |file| download_blob_to(file) }
MiniMagick::Image.create(blob.filename.extension_with_delimiter) { |file| download_blob_to(file) }
end
def transform(image)

View File

@ -18,7 +18,15 @@ module ActiveStorage
config.active_storage.analyzers = [ ActiveStorage::Analyzer::ImageAnalyzer, ActiveStorage::Analyzer::VideoAnalyzer ]
config.active_storage.paths = ActiveSupport::OrderedOptions.new
config.active_storage.variable_content_types = %w( image/png image/gif image/jpg image/jpeg image/vnd.adobe.photoshop )
config.active_storage.variable_content_types = %w(
image/png
image/gif
image/jpg
image/jpeg
image/vnd.adobe.photoshop
image/vnd.microsoft.icon
)
config.active_storage.content_types_to_serve_as_binary = %w(
text/html
text/javascript

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -50,6 +50,17 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
assert_equal 20, image.height
end
test "resized variation of ICO blob" do
blob = create_file_blob(filename: "favicon.ico", content_type: "image/vnd.microsoft.icon")
variant = blob.variant(resize: "20x20").processed
assert_match(/icon\.png/, variant.service_url)
image = read_image(variant)
assert_equal "PNG", image.type
assert_equal 20, image.width
assert_equal 20, image.height
end
test "optimized variation of GIF blob" do
blob = create_file_blob(filename: "image.gif", content_type: "image/gif")