diff options
author | George Claghorn <george.claghorn@gmail.com> | 2018-02-24 15:27:53 -0500 |
---|---|---|
committer | George Claghorn <george.claghorn@gmail.com> | 2018-02-24 15:27:57 -0500 |
commit | 3915a470d2b8898fdbc384d0f9f31e2ad8a2c899 (patch) | |
tree | fee562827a93af6ebec14543f6106c1fc1248e5b | |
parent | d04b5179ffc26ab7bfd7210e1103f5ab4f1bd54f (diff) | |
download | rails-3915a470d2b8898fdbc384d0f9f31e2ad8a2c899.tar.gz rails-3915a470d2b8898fdbc384d0f9f31e2ad8a2c899.tar.bz2 rails-3915a470d2b8898fdbc384d0f9f31e2ad8a2c899.zip |
Support varying ICO files
Closes #32096.
-rw-r--r-- | activestorage/app/models/active_storage/variant.rb | 2 | ||||
-rw-r--r-- | activestorage/lib/active_storage/engine.rb | 10 | ||||
-rw-r--r-- | activestorage/test/fixtures/files/favicon.ico | bin | 0 -> 16958 bytes | |||
-rw-r--r-- | activestorage/test/models/variant_test.rb | 11 |
4 files changed, 21 insertions, 2 deletions
diff --git a/activestorage/app/models/active_storage/variant.rb b/activestorage/app/models/active_storage/variant.rb index e08a2271ec..a95a4bfd7c 100644 --- a/activestorage/app/models/active_storage/variant.rb +++ b/activestorage/app/models/active_storage/variant.rb @@ -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) diff --git a/activestorage/lib/active_storage/engine.rb b/activestorage/lib/active_storage/engine.rb index 8ba32490b1..9430dde028 100644 --- a/activestorage/lib/active_storage/engine.rb +++ b/activestorage/lib/active_storage/engine.rb @@ -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 diff --git a/activestorage/test/fixtures/files/favicon.ico b/activestorage/test/fixtures/files/favicon.ico Binary files differnew file mode 100644 index 0000000000..87192a8a07 --- /dev/null +++ b/activestorage/test/fixtures/files/favicon.ico diff --git a/activestorage/test/models/variant_test.rb b/activestorage/test/models/variant_test.rb index 0cf8a583bd..0f3ada25c0 100644 --- a/activestorage/test/models/variant_test.rb +++ b/activestorage/test/models/variant_test.rb @@ -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") |