diff options
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | Gemfile.lock | 11 | ||||
-rw-r--r-- | activestorage/README.md | 4 | ||||
-rw-r--r-- | activestorage/app/models/active_storage/variation.rb | 22 | ||||
-rw-r--r-- | activestorage/test/models/variant_test.rb | 14 |
5 files changed, 41 insertions, 12 deletions
@@ -61,7 +61,7 @@ group :job do gem "resque-scheduler", require: false gem "sidekiq", require: false gem "sucker_punch", require: false - gem "delayed_job", require: false + gem "delayed_job", require: false, github: "collectiveidea/delayed_job" gem "queue_classic", github: "QueueClassic/queue_classic", branch: "master", require: false, platforms: :ruby gem "sneakers", require: false gem "que", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 8dc20f1ad3..a4f24600c6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,6 +7,13 @@ GIT pg (>= 0.17, < 0.20) GIT + remote: https://github.com/collectiveidea/delayed_job.git + revision: 6cf9b0b2c256d20148172d074ca60e13d6439903 + specs: + delayed_job (4.1.3) + activesupport (>= 3.0, < 5.2) + +GIT remote: https://github.com/matthewd/rb-inotify.git revision: 856730aad4b285969e8dd621e44808a7c5af4242 branch: close-handling @@ -201,8 +208,6 @@ GEM dante (0.2.0) declarative (0.0.10) declarative-option (0.1.0) - delayed_job (4.1.3) - activesupport (>= 3.0, < 5.2) delayed_job_active_record (4.1.2) activerecord (>= 3.0, < 5.2) delayed_job (>= 3.0, < 5) @@ -513,7 +518,7 @@ DEPENDENCIES chromedriver-helper coffee-rails dalli (>= 2.2.1) - delayed_job + delayed_job! delayed_job_active_record google-cloud-storage (~> 1.8) hiredis 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 |