1. 21 5月, 2018 1 次提交
    • J
      Disable variant options when false or nil present · 0210ac0b
      Jacob Smith 提交于
      In response to https://github.com/rails/rails/issues/32917
      
      In the current implementation, ActiveStorage passes all options to the underlying processor,
      including when a key has a value of false.
      
      For example, passing:
      
      ```
      avatar.variant(resize: "100x100", monochrome: false, flip: "-90")
      ```
      
      will return a monochrome image (or an error, pending on ImageMagick configuration) because
      it passes `-monochrome false` to the command (but the command line does not allow disabling
      flags this way, as usually a user would omit the flag entirely to disable that feature).
      
      This fix only passes those keys forward to the underlying processor if the value responds to
      `present?`. In practice, this means that `false` or `nil` will be filtered out before going
      to the processor.
      
      One possible use case would be for a user to be able to apply different filters to an avatar.
      The code might look something like:
      
      ```
        variant_options = {
          monochrome: params[:monochrome],
          resize:     params[:resize]
        }
      
        avatar.variant(*variant_options)
      ```
      
      Obviously some sanitization may be beneficial in a real-world scenario, but this type of
      configuration object could be used in many other places as well.
      
      - Add removing falsy values from varaints to changelog
      
      - The entirety of #image_processing_transformation inject block was wrapped in `list.tap`
       to guard against the default `nil` being returned if no conditional was called.
      
      - add test for explicitly true variant options
      0210ac0b
  2. 23 4月, 2018 2 次提交
  3. 18 4月, 2018 1 次提交
    • J
      Use ImageProcessing gem for ActiveStorage variants · ca129685
      Janko Marohnić 提交于
      ImageProcessing gem is a wrapper around MiniMagick and ruby-vips, and
      implements an interface for common image resizing and processing. This
      is the canonical image processing gem recommended in [Shrine], and
      that's where it developed from. The initial implementation was extracted
      from Refile, which also implements on-the-fly transformations.
      
      Some features that ImageProcessing gem adds on top of MiniMagick:
      
        * resizing macros
          - #resize_to_limit
          - #resize_to_fit
          - #resize_to_fill
          - #resize_and_pad
        * automatic orientation
        * automatic thumbnail sharpening
        * avoids the complex and inefficient MiniMagick::Image class
        * will use "magick" instead of "convert" on ImageMagick 7
      
      However, the biggest feature of the ImageProcessing gem is that it has
      an alternative implementation that uses libvips. Libvips is an
      alternative to ImageMagick that can process images very rapidly (we've
      seen up 10x faster than ImageMagick).
      
      What's great is that the ImageProcessing gem provides the same interface
      for both implementations. The macros are named the same, and the libvips
      implementation does auto orientation and thumbnail sharpening as well;
      only the operations/options specific to ImageMagick/libvips differ. The
      integration provided by this PR should work for both implementations.
      
      The plan is to introduce the ImageProcessing backend in Rails 6.0 as the
      default backend and deprecate the MiniMagick backend, then in Rails 6.1
      remove the MiniMagick backend.
      ca129685
  4. 25 2月, 2018 1 次提交
  5. 16 1月, 2018 1 次提交
  6. 11 1月, 2018 1 次提交
  7. 02 1月, 2018 1 次提交
  8. 22 12月, 2017 1 次提交
  9. 18 12月, 2017 1 次提交
  10. 15 12月, 2017 1 次提交
  11. 06 10月, 2017 1 次提交
  12. 29 9月, 2017 1 次提交
  13. 14 8月, 2017 1 次提交
  14. 12 8月, 2017 1 次提交
  15. 05 8月, 2017 1 次提交
    • Y
      Fix ruby warnings · 46db463d
      yuuji.yaginuma 提交于
      This fixes following warnings:
      
      ```
      test/models/variant_test.rb:11: warning: ambiguous first argument; put parentheses or a space even after `/' operator
      lib/active_storage/attached/macros.rb:63: warning: instance variable @active_storage_attached_highlights not initialized
      lib/active_storage/attached/macros.rb:25: warning: instance variable @active_storage_attached_avatar not initialized
      ```
      46db463d