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