Method: Scrivito::Binary#transform
- Defined in:
- app/cms/scrivito/binary.rb
#transform(definition) ⇒ Scrivito::Binary
Use this method to transform images, i.e. to scale down large images or to generate thumbnails of images. Only applicable if this Scrivito::Binary is an image.
This method does not change the binary. Instead, it returns a copy of it, transformed using the definition
.
If the original binary has already been transformed, the returned binary will be a combination of the transformations. Thus, the transformations can be chained (see examples).
The transformed data is calculated “lazily”, so calling #transform does not trigger any calculation. The calculation is triggered only when data is accessed, for example via #url.
Note that transforming images is slow and therefore should not be carried out inside a request. The #scrivito_image_tag and #scrivito_path helpers transform images asynchronously and don’t place additional load onto requests.
277 278 279 280 281 282 |
# File 'app/cms/scrivito/binary.rb', line 277 def transform(definition) self.class.new(id, public?, transformation_definition: (transformation_definition || {}).merge(definition), original: original, obj_id: obj_id) end |