Adding custom Active Storage transformations

Curated ago by @jeremysmithco

Description

Out of the box, Active Storage supports a number of transformations, through the image_processing gem. This gem provides a common interface to both MiniMagick (the old standard) and ruby-vips (the new default).

I recently needed the ability to lighten images uploaded via Active Storage (for use as watermarks), but there isn’t a built-in method to do this through the transformations interface. However, I discovered that you can register your own custom ImageProcessing methods like this. (Thanks to this blog post for the approach.)

1
2
3
require 'image_processing/vips/custom_processing'

ImageProcessing::Vips::Processor.include(ImageProcessing::Vips::CustomProcessing)

Register the custom processing method.