Skip to Content Skip to Search

Active Storage Transformers Transformer

A Transformer applies a set of transformations to an image.

The following concrete subclasses are included in Active Storage:

An application can set config.active_storage.variant_processor to a class. The class must implement the interface defined by Transformer. Active Storage then uses it for variant processing.

Methods
N
P
T

Attributes

[R] transformations

Class Public methods

new(transformations)

# File activestorage/lib/active_storage/transformers/transformer.rb, line 20
def initialize(transformations)
  @transformations = transformations
end

Instance Public methods

transform(file, format:)

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.

# File activestorage/lib/active_storage/transformers/transformer.rb, line 27
def transform(file, format:)
  output = process(file, format: format)

  begin
    yield output
  ensure
    output.close!
  end
end

Instance Private methods

process(file, format:)

Returns an open Tempfile containing a transformed image in the given format. All subclasses implement this method.

# File activestorage/lib/active_storage/transformers/transformer.rb, line 40
def process(file, format:) # :doc:
  raise NotImplementedError
end