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
- #histogram ⇒ Object
-
#initialize(src_image_path, image_type = nil) ⇒ DominantColors
constructor
A new instance of DominantColors.
- #sorted_pixels ⇒ Object
- #to_cmyk ⇒ Object
- #to_hex ⇒ Object
- #to_hsl ⇒ Object
- #to_rgb ⇒ Object
- #to_rgba ⇒ Object
- #to_yiq ⇒ Object
Constructor Details
#initialize(src_image_path, image_type = nil) ⇒ DominantColors
Returns a new instance of DominantColors.
7 8 9 10 |
# File 'lib/miro/dominant_colors.rb', line 7 def initialize(src_image_path, image_type = nil) @src_image_path = src_image_path @image_type = image_type end |
Instance Attribute Details
#src_image_path ⇒ Object
Returns the value of attribute src_image_path.
5 6 7 |
# File 'lib/miro/dominant_colors.rb', line 5 def src_image_path @src_image_path end |
Instance Method Details
#by_percentage ⇒ Object
39 40 41 42 43 44 |
# File 'lib/miro/dominant_colors.rb', line 39 def by_percentage return nil if Miro.histogram? sorted_pixels pixel_count = @pixels.size sorted_pixels.collect { |pixel| @grouped_pixels[pixel].size / pixel_count.to_f } end |
#histogram ⇒ Object
50 51 52 |
# File 'lib/miro/dominant_colors.rb', line 50 def histogram @histogram ||= downsample_and_histogram.sort_by { |item| item[0] }.reverse end |
#sorted_pixels ⇒ Object
46 47 48 |
# File 'lib/miro/dominant_colors.rb', line 46 def sorted_pixels @sorted_pixels ||= extract_colors_from_image end |
#to_cmyk ⇒ Object
31 32 33 |
# File 'lib/miro/dominant_colors.rb', line 31 def to_cmyk histogram.map { |item| item[1].to_cmyk.to_a } if Miro.histogram? end |
#to_hex ⇒ Object
12 13 14 15 |
# File 'lib/miro/dominant_colors.rb', line 12 def to_hex return histogram.map{ |item| item[1].html } if Miro.histogram? sorted_pixels.collect { |pixel| ChunkyPNG::Color.to_hex(pixel, false) } end |
#to_hsl ⇒ Object
27 28 29 |
# File 'lib/miro/dominant_colors.rb', line 27 def to_hsl histogram.map { |item| item[1].to_hsl.to_a } if Miro.histogram? end |
#to_rgb ⇒ Object
17 18 19 20 |
# File 'lib/miro/dominant_colors.rb', line 17 def to_rgb return histogram.map { |item| item[1].to_rgb.to_a } if Miro.histogram? sorted_pixels.collect { |pixel| ChunkyPNG::Color.to_truecolor_bytes(pixel) } end |
#to_rgba ⇒ Object
22 23 24 25 |
# File 'lib/miro/dominant_colors.rb', line 22 def to_rgba return histogram.map { |item| item[1].css_rgba } if Miro.histogram? sorted_pixels.collect { |pixel| ChunkyPNG::Color.to_truecolor_alpha_bytes(pixel) } end |
#to_yiq ⇒ Object
35 36 37 |
# File 'lib/miro/dominant_colors.rb', line 35 def to_yiq histogram.map { |item| item[1].to_yiq.to_a } if Miro.histogram? end |