Processors
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 call
(MyProcessor
in this case)
Using the processor
The processor is available as a method to Job
objects
and Attachment
objects
Furthermore, a bang! method is provided, which operates on self
You can pass arguments, which will be passed on to the processor block
Implementing the processor
The 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 add_meta
NOTE meta data should be serializable to and from JSON.
Using shell commands
To update using the shell, you can use Content#shell_update
The yielded old_path
and new_path
above will always exist.
By default every argument is shell-escaped so pipes, etc. won’t work.
You can avoid this with escape: false
.
Change the output extension with the :ext
option.
Using pre-registered processors
To update using a pre-registered processor, use Content#process!
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
A job
will have a url
Here, basename
, style
and ext
have not been set on the job’s url_attributes
, so they don’t appear in the url.
Setting the name will set basename
and ext
.
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 update_url
(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 update_url
.
ImageMagick
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 Dragonfly::ImageMagick::Commands
, e.g.
which corresponds to the command-line
convert <original_path> -sigmoidal-contrast 4,0% <new_path>
As with thumb
, you can specify a few more options
Derived from theme by orderedlist