项目作者: OpenGems

项目描述 :
Extract the dominant color(s) from an image (remote image, locally image, base64 image etc...)
高级语言: Ruby
项目地址: git://github.com/OpenGems/rails_dominant_colors.git
创建时间: 2020-05-02T22:55:06Z
项目社区:https://github.com/OpenGems/rails_dominant_colors

开源协议:MIT License

下载


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:

  1. gem 'rails_dominant_colors'

And then execute:

  1. $ bundle install

Or install it yourself as:

  1. $ gem install rails_dominant_colors

Usage

  1. colors = 5 # Optional, number of colors (default: 5)
  2. dominant_colors = RailsDominantColors::Base64.new('data:image/png;base64,awesome-image', colors)
  3. # or
  4. RailsDominantColors::Url.new('https://awesome-url.com/awesome-image.png', colors)
  5. # or
  6. RailsDominantColors::Path.new('/awesome/path/awesome-image.png', colors)
  7. # and
  8. dominant_colors.to_hex # => ["#FF007F", "#000000", "#1C000F", "#A0004F", "#000000"]
  9. dominant_colors.to_hex_alpha # => ["#FF007FFF", "#00000000", "#1C000FFE", "#A0004FFF", "#0000005F"]
  10. dominant_colors.to_rgb # => [[255, 0, 127], [0, 0, 0], [28, 0, 15], [160, 0, 79], [0, 0, 0]]
  11. 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]]
  12. dominant_colors.to_hsl # => [[330, 100, 50], [0, 0, 0], [328, 100, 5], [330, 100, 31], [0, 0, 0]]
  13. 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]]
  14. # Awesome bonus
  15. 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.