Class: Miro::DominantColors

Inherits:
Object
  • Object
show all
Defined in:
lib/miro/dominant_colors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_pathObject

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_percentageObject



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_pixelsObject



27
28
29
# File 'lib/miro/dominant_colors.rb', line 27

def sorted_pixels
  @sorted_pixels ||= extract_colors_from_image
end

#to_hexObject



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_rgbObject



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_rgbaObject



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