Merge PR #50953
This commit is contained in:
commit
fdc5ec228e
@ -1,3 +1,8 @@
|
||||
* Add `image/webp` to `config.active_storage.web_image_content_types` when `load_defaults "7.2"`
|
||||
is set.
|
||||
|
||||
*Lewis Buckley*
|
||||
|
||||
* Fix JSON-encoding of `ActiveStorage::Filename` instances.
|
||||
|
||||
*Jonathan del Strother*
|
||||
|
BIN
activestorage/test/fixtures/files/valley.webp
vendored
Normal file
BIN
activestorage/test/fixtures/files/valley.webp
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
@ -114,6 +114,17 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
|
||||
assert_equal 8, image.height
|
||||
end
|
||||
|
||||
test "resized variation of WEBP blob" do
|
||||
blob = create_file_blob(filename: "valley.webp")
|
||||
variant = blob.variant(resize_to_limit: [50, 50]).processed
|
||||
assert_match(/valley\.webp/, variant.url)
|
||||
|
||||
image = read_image(variant)
|
||||
assert_equal "WEBP", image.type
|
||||
assert_equal 50, image.width
|
||||
assert_equal 33, image.height
|
||||
end
|
||||
|
||||
test "optimized variation of GIF blob" do
|
||||
blob = create_file_blob(filename: "image.gif", content_type: "image/gif")
|
||||
|
||||
|
@ -60,6 +60,7 @@ Below are the default values associated with each target version. In cases of co
|
||||
|
||||
#### Default Values for Target Version 7.2
|
||||
|
||||
- [`config.active_storage.web_image_content_types`](#config-active-storage-web-image-content-types): `%w[image/png image/jpeg image/gif image/webp]`
|
||||
- [`config.active_record.validate_migration_timestamps`](#config-active-record-validate-migration-timestamps): `true`
|
||||
|
||||
#### Default Values for Target Version 7.1
|
||||
@ -2865,13 +2866,14 @@ config.active_storage.variable_content_types = %w(image/png image/gif image/jpeg
|
||||
|
||||
Accepts an array of strings regarded as web image content types in which
|
||||
variants can be processed without being converted to the fallback PNG format.
|
||||
If you want to use `WebP` or `AVIF` variants in your application you can add
|
||||
`image/webp` or `image/avif` to this array.
|
||||
By default, this is defined as:
|
||||
For example, if you want to use `AVIF` variants in your application you can add
|
||||
`image/avif` to this array.
|
||||
|
||||
```ruby
|
||||
config.active_storage.web_image_content_types = %w(image/png image/jpeg image/gif)
|
||||
```
|
||||
The default value depends on the `config.load_defaults` target version:
|
||||
| Starting with version | The default value is |
|
||||
| --------------------- | ----------------------------------------------- |
|
||||
| (original) | `%w(image/png image/jpeg image/gif)` |
|
||||
| 7.2 | `%w(image/png image/jpeg image/gif image/webp)` |
|
||||
|
||||
#### `config.active_storage.content_types_to_serve_as_binary`
|
||||
|
||||
|
@ -324,6 +324,10 @@ def load_defaults(target_version)
|
||||
when "7.2"
|
||||
load_defaults "7.1"
|
||||
|
||||
if respond_to?(:active_storage)
|
||||
active_storage.web_image_content_types = %w( image/png image/jpeg image/gif image/webp )
|
||||
end
|
||||
|
||||
if respond_to?(:active_record)
|
||||
active_record.validate_migration_timestamps = true
|
||||
end
|
||||
|
@ -9,6 +9,14 @@
|
||||
# Read the Guide for Upgrading Ruby on Rails for more info on each option.
|
||||
# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html
|
||||
|
||||
###
|
||||
# Adds image/webp to the list of content types Active Storage considers as an image
|
||||
# Prevents automatic conversion to a fallback PNG, and assumes clients support WebP, as they support gif, jpeg, and png.
|
||||
# This is possible due to broad browser support for WebP, but older browsers and email clients may still not support
|
||||
# WebP. Requires imagemagick/libvips built with WebP support.
|
||||
#++
|
||||
# Rails.application.config.active_storage.web_image_content_types = %w[image/png image/jpeg image/gif image/webp]
|
||||
|
||||
###
|
||||
# Enable validation of migration timestamps. When set, an ActiveRecord::InvalidMigrationTimestampError
|
||||
# will be raised if the timestamp prefix for a migration is more than a day ahead of the timestamp
|
||||
|
Loading…
Reference in New Issue
Block a user