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.
- #reduce_size(width, height) ⇒ Object
- #remove_bg(nc, fuzz = 20) ⇒ Object
- #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 |
#reduce_size(width, height) ⇒ Object
20 21 22 |
# File 'lib/prizm.rb', line 20 def reduce_size(width, height) @image.change_geometry!("#{width}x#{height}") { |cols, rows, img| img.resize!(cols, rows) } end |
#remove_bg(nc, fuzz = 20) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/prizm.rb', line 24 def remove_bg(nc, fuzz=20) image = reduce_size(100, 100) image = image.border(1, 1, image.pixel_color(0,0)) image = image.quantize(nc+4) image.fuzz = "#{fuzz}%" a = image.color_floodfill(0, 0, image.pixel_color(0,0)) a = a.matte_floodfill(0,0) 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 |