Class: ActiveStorage::Transformers::Transformer
- Inherits:
-
Object
- Object
- ActiveStorage::Transformers::Transformer
- Defined in:
- lib/active_storage/transformers/transformer.rb
Overview
A Transformer applies a set of transformations to an image.
The following concrete subclasses are included in Active Storage:
-
ActiveStorage::Transformers::ImageProcessingTransformer: backed by ImageProcessing, a common interface for MiniMagick and ruby-vips
Direct Known Subclasses
Instance Attribute Summary collapse
-
#transformations ⇒ Object
readonly
Returns the value of attribute transformations.
Instance Method Summary collapse
-
#initialize(transformations) ⇒ Transformer
constructor
A new instance of Transformer.
-
#transform(file, format:) ⇒ Object
Applies the transformations to the source image in
file
, producing a target image in the specifiedformat
.
Constructor Details
#initialize(transformations) ⇒ Transformer
Returns a new instance of Transformer.
14 15 16 |
# File 'lib/active_storage/transformers/transformer.rb', line 14 def initialize(transformations) @transformations = transformations end |
Instance Attribute Details
#transformations ⇒ Object (readonly)
Returns the value of attribute transformations.
12 13 14 |
# File 'lib/active_storage/transformers/transformer.rb', line 12 def transformations @transformations end |
Instance Method Details
#transform(file, format:) ⇒ Object
Applies the transformations to the source image in file
, producing a target image in the specified format
. Yields an open Tempfile containing the target image. Closes and unlinks the output tempfile after yielding to the given block. Returns the result of the block.
21 22 23 24 25 26 27 28 29 |
# File 'lib/active_storage/transformers/transformer.rb', line 21 def transform(file, format:) output = process(file, format: format) begin yield output ensure output.close! end end |