module Shrine::Plugins::Color::InstanceMethods
Constants
- DEFAULT_PALETTE_HEXES
Public Instance Methods
dominant_color(io_path)
click to toggle source
Returns the most dominant color in HEX in an image.
# File lib/shrine/plugins/color.rb, line 19 def dominant_color(io_path) histogram = Colorscore::Histogram.new(io_path, :colors => 1) color = histogram.colors.first color && color.html # html = hex end
palette_color(io_path, color_count = 1, palette_hexes = DEFAULT_PALETTE_HEXES)
click to toggle source
Matches the dominant color to the closest color in the array provided
# File lib/shrine/plugins/color.rb, line 26 def palette_color(io_path, color_count = 1, palette_hexes = DEFAULT_PALETTE_HEXES) histogram = Colorscore::Histogram.new(io_path) palette = Colorscore::Palette.from_hex(palette_hexes) histogram_scores = histogram.scores return nil if histogram_scores.first.last.nil? scores = palette.scores(histogram_scores, 1) scores.first(color_count).map { |_score, color| color.html} end