Class: DragonflyLibvips::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/dragonfly_libvips/plugin.rb

Instance Method Summary collapse

Instance Method Details

#call(app, _opts = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dragonfly_libvips/plugin.rb', line 11

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|
    c.analyse(:image_properties).key?("format")
  rescue ::Vips::Error
    false
  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