Rails show rgb color string as color swatch -


im using rmagick take average color of image user uploads. , i've got down displaying rgb format. i'd take rgb string , display color swatch on page...any idea on how accomplish this?

{:r=>155, :g=>132, :b=>118} 

# controller @image = magick::image.read(@design.photo.path).first average_color = # magick method return average color # average " {:r=>155, :g=>132, :b=>118} " @average_color_string = "##{average_color.values.map{|v| v.to_s(16) }.join}"  #view average color: <%= @average_color_string %> 

should display this:

average color: #9b8476

the .to_s(16) converts integer 16-based string, known hexadecimal.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -