Class: Prizm::Extractor
- Inherits:
-
Object
- Object
- Prizm::Extractor
- Defined in:
- lib/prizm.rb
Instance Method Summary collapse
- #get_colors(nc = 6, remove_bg = true) ⇒ Object
-
#initialize(img_location) ⇒ Extractor
constructor
A new instance of Extractor.
- #to_hex(pixel) ⇒ Object
Constructor Details
#initialize(img_location) ⇒ Extractor
Returns a new instance of Extractor.
6 7 8 |
# File 'lib/prizm.rb', line 6 def initialize(img_location) @image = Magick::ImageList.new(img_location) end |
Instance Method Details
#get_colors(nc = 6, remove_bg = true) ⇒ Object
10 11 12 13 14 |
# File 'lib/prizm.rb', line 10 def get_colors(nc=6, remove_bg=true) image = remove_bg ? remove_bg(nc) : reduce_size(100, 100) q = image.quantize(nc) colors = q.color_histogram.sort {|a, b| b[1] <=> a[1]}.map { |color, count| color } end |
#to_hex(pixel) ⇒ Object
16 17 18 |
# File 'lib/prizm.rb', line 16 def to_hex(pixel) pixel.to_color(Magick::AllCompliance, false, 8) end |