Sha256: 3d6ed6a3e864f2c412cb8059418a2815e555973eab60317b2e6862dfd1579a59

Contents?: true

Size: 1.85 KB

Versions: 60

Compression:

Stored size: 1.85 KB

Contents

Processing
==========
Registered processors allow you to modify data, e.g. resizing an image.

You can register as many processors as you like.

Let's say we have a Dragonfly app

    app = Dragonfly[:images]

and an image object (actually a {Dragonfly::Job Job} object)...

    image = app.fetch('some/uid')

...OR a Dragonfly model accessor...

    image = @album.cover_image

We can process it using any processing methods that have been registered with the processor.

Lazy evaluation
---------------

    new_image = image.process(:some_method)

doesn't actually do anything until you call something on the returned {Dragonfly::Job Job} object, like `url`, `data`, etc.

Bang method
-----------

    image.process!(:some_method)

modifies the image object itself, rather than returning a new object.

ImageMagick Processor
---------------------
See {file:ImageMagick}.

Custom Processors
-----------------

To register a single custom processor:

    app.processor.add :watermark do |temp_object, *args|
      # use temp_object.data, temp_object.path, temp_object.file, etc.
      SomeLibrary.add_watermark(temp_object.data, 'some/watermark/file.png')
      # return a String, Pathname, File or Tempfile
    end

    new_image = image.process(:watermark)

You can create a class like the ImageMagick one above, in which case all public methods will be counted as processing methods.
Each method takes the temp_object as its argument, plus any other args.

    class MyProcessor

      def coolify(temp_object, opts={})
        SomeLib.coolify(temp_object.data, opts)
      end

      def uglify(temp_object, ugliness)
        `uglify -i #{temp_object.path} -u #{ugliness}`
      end

      private

      def my_helper_method
        # do stuff
      end

    end

    app.processor.register(MyProcessor)

    new_image = image.coolify(:some => :args)

    new_image = image.uglify(:loads)

Version data entries

60 entries across 60 versions & 3 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/dragonfly-0.9.12/extra_docs/Processing.md
classiccms-0.7.4 vendor/bundle/gems/dragonfly-0.9.12/extra_docs/Processing.md
classiccms-0.7.3 vendor/bundle/gems/dragonfly-0.9.12/extra_docs/Processing.md
classiccms-0.7.2 vendor/bundle/gems/dragonfly-0.9.12/extra_docs/Processing.md
classiccms-0.7.1 vendor/bundle/gems/dragonfly-0.9.12/extra_docs/Processing.md
classiccms-0.7.0 vendor/bundle/gems/dragonfly-0.9.12/extra_docs/Processing.md
dragonfly-0.9.15 extra_docs/Processing.md
dragonfly-0.9.14 extra_docs/Processing.md
dragonfly-0.9.13 extra_docs/Processing.md
classiccms-0.6.9 vendor/bundle/gems/dragonfly-0.9.12/extra_docs/Processing.md
classiccms-0.6.8 vendor/bundle/gems/dragonfly-0.9.12/extra_docs/Processing.md
classiccms-0.6.7 vendor/bundle/gems/dragonfly-0.9.12/extra_docs/Processing.md
classiccms-0.6.6 vendor/bundle/gems/dragonfly-0.9.12/extra_docs/Processing.md
classiccms-0.6.5 vendor/bundle/gems/dragonfly-0.9.12/extra_docs/Processing.md
classiccms-0.6.4 vendor/bundle/gems/dragonfly-0.9.12/extra_docs/Processing.md
classiccms-0.6.3 vendor/bundle/gems/dragonfly-0.9.12/extra_docs/Processing.md
classiccms-0.6.2 vendor/bundle/gems/dragonfly-0.9.12/extra_docs/Processing.md
classiccms-0.6.1 vendor/bundle/gems/dragonfly-0.9.12/extra_docs/Processing.md
classiccms-0.6.0 vendor/bundle/gems/dragonfly-0.9.12/extra_docs/Processing.md
classiccms-0.5.17 vendor/bundle/gems/dragonfly-0.9.12/extra_docs/Processing.md