Takes an image (path or url) and extracts the 7 most common colors and returns their hex values.

Source Code : 
def extract_colors(src)
    
image Magick::ImageList.new(src)
    
colors = []
    
image.quantize(7Magick::RGBColorspace)
    
palette q.color_histogram.sort {|abb[1] <=> a[1]}
 
    (
0..6).each do |i|
        
palette[i].to_s.split(',').map {|xx[/\d+/]}
        
c.pop
        c
[0], c[1], c[2] = [c[0], c[1], c[2]].map { |s
            
s.to_i
            
if 255 # not all ImageMagicks are created equal....
                
255
            end
            s 
s.to_s(16)
            if 
s.size == 
                
'0' s
            
else
                
s

[Login or Register to remove this advertisement]

            end
        
}
        
colors << '#' c.join('')
    
end
 
    
return colors
end 
Mobile_Guru Reviewed by Mobile_Guru on . Extract most common colors from an image Takes an image (path or url) and extracts the 7 most common colors and returns their hex values. def extract_colors(src) image = Magick::ImageList.new(src) colors = q = image.quantize(7, Magick::RGBColorspace) palette = q.color_histogram.sort {|a, b| b <=> a} (0..6).each do |i| c = palette.to_s.split(',').map {|x| x} Rating: 5