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



8
9
10
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/dragonfly_libvips/plugin.rb', line 8

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

  app.add_analyser :width do |content|
    content.analyse(:image_properties)['width']
  end

  app.add_analyser :height do |content|
    content.analyse(:image_properties)['height']
  end

  app.add_analyser :xres do |content|
    content.analyse(:image_properties)['xres']
  end

  app.add_analyser :yres do |content|
    content.analyse(:image_properties)['yres']
  end

  app.add_analyser :format do |content|
    content.analyse(:image_properties)['format']
  end

  app.add_analyser :aspect_ratio do |content|
    attrs = content.analyse(:image_properties)
    attrs['width'].to_f / attrs['height']
  end

  app.add_analyser :portrait do |content|
    attrs = content.analyse(:image_properties)
    attrs['width'] <= attrs['height']
  end

  app.add_analyser :landscape do |content|
    !content.analyse(:portrait)
  end

  app.add_analyser :image do |content|
    begin
      content.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 :thumb, Processors::Thumb.new
  app.add_processor :rotate, Processors::Rotate.new
end