class
ActiveStorage::VariantProcessor
- ActiveStorage::VariantProcessor
- Reference
- Object
Overview
Runs the transformations of a variation over an image and encodes the result.
Rails reaches the image_processing gem through Transformers::ImageProcessingTransformer, and
picks the backend with config.active_storage.variant_processor, which is :vips from
load_defaults 7.0 on. A subclass here plays the part of one of that gem's processors.
Rails checks every transformation name against
ActiveStorage.supported_image_processing_methods before running it, because a variation names
a method to call. A subclass must do the same and raise UnsupportedImageProcessingMethod for
anything it does not implement: a transformation that is skipped silently stores the wrong image
under a digest that says it is right, and nothing recomputes it afterwards.
https://github.com/rails/rails/blob/v8.1.3/activestorage/lib/active_storage/transformers/image_processing_transformer.rb
This base class is also the default of ActiveStorage.variant_processor, and it processes
nothing. A backend binds a native library, and Crystal links at compile time, so requiring one
here would make that library a build dependency of every consumer, including the ones that only
generate URLs. An app that serves representations requires a backend and assigns it:
require "marten_rails_bridge/active_storage/variant_processor/vips_processor"
ActiveStorage.variant_processor = ActiveStorage::VariantProcessor::VipsProcessor.new
Direct Known Subclasses
Defined in:
active_storage/variant_processor.crInstance Method Summary
-
#process(source : Bytes, transformations : JSON::Any, format : String) : Bytes
Returns
sourcewithtransformationsapplied, encoded asformat.
Instance Method Detail
Returns source with transformations applied, encoded as format.
transformations carries no format key, matching the transformations.except(:format) that
Rails hands its transformer.
Raises NotImplementedError unless a backend is assigned, as the Rails base service does for
the methods a service has to implement.