Sha256: 85a32f104890e6e9f10822c4647873fc18cfaaf88bafd6a6173d0dcd1ad612b3

Contents?: true

Size: 1.47 KB

Versions: 9

Compression:

Stored size: 1.47 KB

Contents

require 'dragonfly_libvips/analysers/image_properties'
require 'dragonfly_libvips/processors/encode'
require 'dragonfly_libvips/processors/extract_area'
require 'dragonfly_libvips/processors/rotate'
require 'dragonfly_libvips/processors/thumb'

module DragonflyLibvips
  class Plugin
    def call(app, _opts = {})
      # Analysers
      app.add_analyser :image_properties, DragonflyLibvips::Analysers::ImageProperties.new

      %w[ width
          height
          xres
          yres
          format
      ].each do |name|
        app.add_analyser(name) { |c| c.analyse(:image_properties)[name] }
      end

      app.add_analyser(:aspect_ratio) { |c| c.analyse(:width).to_f / c.analyse(:height).to_f }
      app.add_analyser(:portrait) { |c| c.analyse(:aspect_ratio) < 1.0 }
      app.add_analyser(:landscape) { |c| !c.analyse(:portrait) }

      app.add_analyser(:image) do |c|
        begin
          c.analyse(:image_properties).key?('format')
        rescue ::Vips::Error
          false
        end
      end

      # Aliases
      app.define(:portrait?) { portrait }
      app.define(:landscape?) { landscape }
      app.define(:image?) { image }

      # Processors
      app.add_processor :encode, Processors::Encode.new
      app.add_processor :extract_area, Processors::ExtractArea.new
      app.add_processor :thumb, Processors::Thumb.new
      app.add_processor :rotate, Processors::Rotate.new
    end
  end
end

Dragonfly::App.register_plugin(:libvips) { DragonflyLibvips::Plugin.new }

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
dragonfly_libvips-2.5.0 lib/dragonfly_libvips/plugin.rb
dragonfly_libvips-2.4.2 lib/dragonfly_libvips/plugin.rb
dragonfly_libvips-2.4.1 lib/dragonfly_libvips/plugin.rb
dragonfly_libvips-2.4.0 lib/dragonfly_libvips/plugin.rb
dragonfly_libvips-2.3.3 lib/dragonfly_libvips/plugin.rb
dragonfly_libvips-2.3.2 lib/dragonfly_libvips/plugin.rb
dragonfly_libvips-2.3.1 lib/dragonfly_libvips/plugin.rb
dragonfly_libvips-2.3.0 lib/dragonfly_libvips/plugin.rb
dragonfly_libvips-2.2.0 lib/dragonfly_libvips/plugin.rb