Class: FoggyMirror::ImageMagick

Inherits:
Object
  • Object
show all
Defined in:
lib/foggy-mirror/adapters/image_magick.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, command: 'convert') ⇒ ImageMagick

Returns a new instance of ImageMagick.



6
7
8
9
# File 'lib/foggy-mirror/adapters/image_magick.rb', line 6

def initialize(path, command: 'convert')
  @path = path
  @command = command
end

Instance Method Details

#color_samples(res) ⇒ Object



17
18
19
20
21
# File 'lib/foggy-mirror/adapters/image_magick.rb', line 17

def color_samples(res)
  out = `#{@command} #{@path.shellescape} -depth 8 -colors 256 -resize #{res}x#{res}! txt:-`
  validate_pixel_enumeration!(out)
  out.scan(HTML_COLOR_MATCHER)
end

#dominant_colorObject



11
12
13
14
15
# File 'lib/foggy-mirror/adapters/image_magick.rb', line 11

def dominant_color
  out = `#{@command} #{@path.shellescape} -depth 8 -colors 1 -resize 1x1 txt:-`
  validate_pixel_enumeration!(out)
  out.match(HTML_COLOR_MATCHER)[0]
end