跳至内容 跳至搜索

Active Storage Transformers Transformer

Transformer 对图像应用一组转换。

Active Storage 中包含以下具体子类

方法
N
P
T

属性

[R] transformations

类公共方法

new(transformations)

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

实例公共方法

transform(file, format:)

将转换应用于 file 中的源图像,生成指定 format 的目标图像。生成一个包含目标图像的打开的 Tempfile。在生成给定块后关闭并取消链接输出的临时文件。返回该块的结果。

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

  begin
    yield output
  ensure
    output.close!
  end
end

实例私有方法

process(file, format:)

返回一个打开的 Tempfile,其中包含给定 format 中转换的图像。所有子类都实现此方法。

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