aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage
diff options
context:
space:
mode:
Diffstat (limited to 'activestorage')
-rw-r--r--activestorage/README.md4
-rw-r--r--activestorage/app/models/active_storage/variation.rb22
-rw-r--r--activestorage/test/models/variant_test.rb14
3 files changed, 32 insertions, 8 deletions
diff --git a/activestorage/README.md b/activestorage/README.md
index 8af0409ec5..85ab70dac6 100644
--- a/activestorage/README.md
+++ b/activestorage/README.md
@@ -1,6 +1,6 @@
# Active Storage
-Active Storage makes it simple to upload and reference files in cloud services like Amazon S3, Google Cloud Storage, or Microsoft Azure Storage, and attach those files to Active Records. Supports having one main service and mirrors in other services for redundancy. It also provides a disk service for testing or local deployments, but the focus is on cloud storage.
+Active Storage makes it simple to upload and reference files in cloud services like [Amazon S3](https://aws.amazon.com/s3/), [Google Cloud Storage](https://cloud.google.com/storage/docs/), or [Microsoft Azure Storage](https://azure.microsoft.com/en-us/services/storage/), and attach those files to Active Records. Supports having one main service and mirrors in other services for redundancy. It also provides a disk service for testing or local deployments, but the focus is on cloud storage.
Files can be uploaded from the server to the cloud or directly from the client to the cloud.
@@ -144,7 +144,7 @@ Active Storage, with its included JavaScript library, supports uploading directl
Active Storage is released under the [MIT License](https://opensource.org/licenses/MIT).
- ## Support
+## Support
API documentation is at:
diff --git a/activestorage/app/models/active_storage/variation.rb b/activestorage/app/models/active_storage/variation.rb
index fc4305dcc5..09997eb97f 100644
--- a/activestorage/app/models/active_storage/variation.rb
+++ b/activestorage/app/models/active_storage/variation.rb
@@ -46,13 +46,15 @@ class ActiveStorage::Variation
# Accepts an open MiniMagick image instance, like what's returned by <tt>MiniMagick::Image.read(io)</tt>,
# and performs the +transformations+ against it. The transformed image instance is then returned.
def transform(image)
- transformations.each do |method, argument|
- image.mogrify do |command|
- if eligible_argument?(argument)
- command.public_send(method, argument)
- else
- command.public_send(method)
+ transformations.each do |(method, argument)|
+ if method.to_s == "combine_options"
+ image.combine_options do |combination|
+ argument.each do |(method, argument)|
+ pass_transform_argument(combination, method, argument)
+ end
end
+ else
+ pass_transform_argument(image, method, argument)
end
end
end
@@ -66,4 +68,12 @@ class ActiveStorage::Variation
def eligible_argument?(argument)
argument.present? && argument != true
end
+
+ def pass_transform_argument(instance, method, argument)
+ if eligible_argument?(argument)
+ instance.public_send(method, argument)
+ else
+ instance.public_send(method)
+ end
+ end
end
diff --git a/activestorage/test/models/variant_test.rb b/activestorage/test/models/variant_test.rb
index 8eced41ee0..2a96dfb142 100644
--- a/activestorage/test/models/variant_test.rb
+++ b/activestorage/test/models/variant_test.rb
@@ -25,6 +25,20 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
assert_match(/Gray/, image.colorspace)
end
+ test "center-weighted crop of JPEG blob" do
+ blob = create_file_blob(filename: "racecar.jpg")
+ variant = blob.variant(combine_options: {
+ gravity: "center",
+ resize: "100x100^",
+ crop: "100x100+0+0",
+ }).processed
+ assert_match(/racecar\.jpg/, variant.service_url)
+
+ image = read_image(variant)
+ assert_equal 100, image.width
+ assert_equal 100, image.height
+ end
+
test "resized variation of PSD blob" do
blob = create_file_blob(filename: "icon.psd", content_type: "image/vnd.adobe.photoshop")
variant = blob.variant(resize: "20x20").processed