A Processor modifies content, e.g. resizing an image, converting audio to mp3 format, etc.
They can be added using a block
or providing an object that responds to
MyProcessor in this case)
Using the processor
The processor is available as a method to
Furthermore, a bang! method is provided, which operates on
You can pass arguments, which will be passed on to the processor block
Implementing the processor
content object yielded to the block/
call method is a Dragonfly::Content - see the doc for methods it provides.
The processor’s job is to use methods on
content to modify it - the return value of the processor block is not important.
Updating content and metadata
The primary method to use to update content is
Content#update. It can take a String, Pathname, File or Tempfile, and optionally metadata to add.
Another way of updating metadata is with
NOTE meta data should be serializable to and from JSON.
Using shell commands
To update using the shell, you can use
new_path above will always exist.
By default every argument is shell-escaped so pipes, etc. won’t work.
You can avoid this with
Change the output extension with the
Using pre-registered processors
To update using a pre-registered processor, use
Updating the url
It is also possible for a processor to (optionally) update the url for a given job. For example, suppose we have a configured url format
will have a url
ext have not been set on the job’s
url_attributes, so they don’t appear in the url.
Setting the name will set
Note that this happens automatically for models when a
xxx_name accessor is provided.
We can tell our processor to add the
style part of the url by implementing the method
(note that we cannot register the processor as a block in this case)
Now the processor adds the ‘style’ part to the url
If the processor accepts extra arguments then these are also passed to
The ImageMagick plugin adds a few processors - see the doc for more details.
If you’re defining a new processor you can make use of the
convert command in
which corresponds to the command-line
convert <original_path> -sigmoidal-contrast 4,0% <new_path>
thumb, you can specify a few more options