rails_dominant_colors

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)


Keywords
convert-images, hex-color, histogram-filters, hsl-color, image-histogram, imagemagick, rails, rgb-color, ruby
License
MIT
Install
gem install rails_dominant_colors -v 0.1.4

Documentation

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

opts = {
  colors: 5 # Number of colors (default: 5)
}

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

# or

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

# or

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

# and

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

colors.to_rgb # => [[255, 0, 127], [0, 0, 0], [28, 0, 15], [160, 0, 79], [0, 0, 0]]
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]]

colors.to_hsl # => [[330, 100, 50], [0, 0, 0], [328, 100, 5], [330, 100, 31], [0, 0, 0]]
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
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.