Active Storage Transformers Transformer
Transformer
对图像应用一组转换。
Active Storage 中包含以下具体子类
-
ActiveStorage::Transformers::ImageProcessingTransformer
: 由 ImageProcessing 支持,它是 MiniMagick 和 ruby-vips 的通用接口
方法
属性
[R] | transformations |
类公共方法
new(transformations) 链接
源代码:显示 | 在 GitHub 上
# File activestorage/lib/active_storage/transformers/transformer.rb, line 16 def initialize(transformations) @transformations = transformations end
实例公共方法
transform(file, format:) 链接
将转换应用于 file
中的源图像,生成指定 format
的目标图像。生成一个包含目标图像的打开的 Tempfile。在生成给定块后关闭并取消链接输出的临时文件。返回该块的结果。
源代码:显示 | 在 GitHub 上
# 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
中转换的图像。所有子类都实现此方法。
来源:显示 | 在 GitHub 上
# File activestorage/lib/active_storage/transformers/transformer.rb, line 36 def process(file, format:) # :doc: raise NotImplementedError end