Class: Miro::DominantColors
- Inherits:
-
Object
- Object
- Miro::DominantColors
- Defined in:
- lib/miro/dominant_colors.rb
Instance Attribute Summary collapse
-
#src_image_path ⇒ Object
Returns the value of attribute src_image_path.
Instance Method Summary collapse
- #by_percentage ⇒ Object
-
#initialize(src_image_path) ⇒ DominantColors
constructor
A new instance of DominantColors.
- #sorted_pixels ⇒ Object
- #to_hex ⇒ Object
- #to_rgb ⇒ Object
- #to_rgba ⇒ Object
Constructor Details
#initialize(src_image_path) ⇒ DominantColors
Returns a new instance of DominantColors.
5 6 7 |
# File 'lib/miro/dominant_colors.rb', line 5 def initialize(src_image_path) @src_image_path = src_image_path end |
Instance Attribute Details
#src_image_path ⇒ Object
Returns the value of attribute src_image_path.
3 4 5 |
# File 'lib/miro/dominant_colors.rb', line 3 def src_image_path @src_image_path end |
Instance Method Details
#by_percentage ⇒ Object
21 22 23 24 25 |
# File 'lib/miro/dominant_colors.rb', line 21 def by_percentage sorted_pixels pixel_count = @pixels.size sorted_pixels.collect { |pixel| @grouped_pixels[pixel].size / pixel_count.to_f } end |
#sorted_pixels ⇒ Object
27 28 29 |
# File 'lib/miro/dominant_colors.rb', line 27 def sorted_pixels @sorted_pixels ||= extract_colors_from_image end |
#to_hex ⇒ Object
9 10 11 |
# File 'lib/miro/dominant_colors.rb', line 9 def to_hex sorted_pixels.collect {|c| ChunkyPNG::Color.to_hex c, false } end |
#to_rgb ⇒ Object
13 14 15 |
# File 'lib/miro/dominant_colors.rb', line 13 def to_rgb sorted_pixels.collect {|c| ChunkyPNG::Color.to_truecolor_bytes c } end |
#to_rgba ⇒ Object
17 18 19 |
# File 'lib/miro/dominant_colors.rb', line 17 def to_rgba sorted_pixels.collect {|c| ChunkyPNG::Color.to_truecolor_alpha_bytes c } end |