No release in over 3 years
Low commit activity in last 3 years
Extract the dominant color(s) from an image (remote image, locally image, base64 image etc...) Get HEX(A) color(s), RGB(A) color(s), HSL(A) color(s)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 0.8
~> 13.0
~> 3.9
~> 0.16

Runtime

 Project Readme

RailsDominantColors

Gem Version Maintainability Build Status security Gem Coverage Status

A Ruby gem for extract the dominant color(s) from an image (remote image, locally image, base64 image etc...)

Get HEX(A) color(s), RGB(A) color(s) and HSL(A) color(s)

Installation

Add this line to your application's Gemfile:

gem 'rails_dominant_colors'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install rails_dominant_colors

Usage

colors = 5 # Optional, number of colors (default: 5)

dominant_colors = RailsDominantColors::Base64.new('data:image/png;base64,awesome-image', colors)

# or

RailsDominantColors::Url.new('https://awesome-url.com/awesome-image.png', colors)

# or

RailsDominantColors::Path.new('/awesome/path/awesome-image.png', colors)

# and

dominant_colors.to_hex # => ["#FF007F", "#000000", "#1C000F", "#A0004F", "#000000"]
dominant_colors.to_hex_alpha # => ["#FF007FFF", "#00000000", "#1C000FFE", "#A0004FFF", "#0000005F"]

dominant_colors.to_rgb # => [[255, 0, 127], [0, 0, 0], [28, 0, 15], [160, 0, 79], [0, 0, 0]]
dominant_colors.to_rgb_alpha # => [[255, 0, 127, 1.0], [0, 0, 0, 0.0], [28, 0, 15, 1.0], [160, 0, 79, 1.0], [0, 0, 0, 0.37]]

dominant_colors.to_hsl # => [[330, 100, 50], [0, 0, 0], [328, 100, 5], [330, 100, 31], [0, 0, 0]]
dominant_colors.to_hsl_alpha # => [[330, 100, 50, 1.0], [0, 0, 0, 0.0], [328, 100, 5, 1.0], [330, 100, 31, 1.0], [0, 0, 0, 0.37]]

# Awesome bonus
dominant_colors.to_pct # => [52.16, 37.45, 9.93, 0.35, 0.1]

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/OpenGems/rails_dominant_colors. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.