Jan 9 2013

Color Parser Gem
Comments Off

On SportSpyder we display a small icon for every source we use. To keep things fresh we sample and use colors from that source’s website when we can. It was a tedious process to build images for each source, but fortunately we wizened to using CSS for this. However, we still needed a faster way to sample colors from a website.

Enter to the Color Parser Ruby Gem. This gem lets you pass in a website’s URL, and the script will parse out the stylesheets to find the colors used in the page:

For example, to get the colors on google.com:

page = ColorParser::Page.new("http://google.com/")
=> {"ffffff"=>5, "c9d7f1"=>1, "0000cc"=>2, "dd8e27"=>1, "990000"=>1, 
    "3366cc"=>3, "000000"=>2, "1111cc"=>5, "cccccc"=>2, "551a8b"=>1}

This gives us the number of occurrences of each color in the styles.

To install:

gem install color_parser

Or add to bundler:

gem "color_parser", "~> 0.0.2"

Sorry, the comment form is closed at this time.