A Ruby gem to help extract the dominant colors from an image.
A Ruby gem to help extract the dominant colors from an image.
Extract the dominant colors from an image.
Questions, Comments, Concerns, or Bugs?
Add this line to your application's Gemfile:
gem 'miro'And then execute:
$ bundleOr install it yourself as:
$ gem install miroConfiguration
# Defaults
Miro.options # => {:image_magick_path => "/usr/bin/convert", :resolution => "150x150", :color_count => 8}
# Setting new options
Miro.options[:image_magick_path] = '/usr/local/bin/convert'
Miro.options[:resolution] = '100x100'
Miro.options[:color_count] = 4
Miro.options[:method] = 'histogram'By default the method option is configured with 'pixel_group' to improve performance change to 'histogram', this will fetch directly from imagemagick the image histogram without any disk operation(read/write) but read the original file.
Initializing an image
# Initialize with a local image
colors = Miro::DominantColors.new('/path/to/local/image.jpg')
# or Initialize with a remote image
colors = Miro::DominantColors.new('http://domain.com/path/to/image.jpg')Retrieving colors from an image
# Hex
colors.to_hex # => ["#51332a", "#2c1d18", "#6c4937", "#65514a", "#95644f", "#e0e7dc", "#a34d3a", "#9fa16b"]
# RGB
colors.to_rgb # => [[81, 51, 42], [44, 29, 24], [108, 73, 55], [101, 81, 74], [149, 100, 79], [224, 231, 220], [163, 77, 58], [159, 161, 107]]
# RGB with Alpha channels
colors.to_rgba # => [[82, 37, 40, 255], [48, 17, 19, 255], [109, 70, 71, 255], [221, 158, 48, 255], [168, 103, 48, 255], [226, 178, 79, 255], [191, 146, 65, 255], [199, 165, 150, 255]]Additional methods only available when histogram method is enabled
…Retrieving percentages of colors disabled on histogram method
# percentage of each color in an image. matches sorting from to_hex,
# to_rgb and to_rgba.
colors.by_percentage # => [0.50, 0.25, 0.15, 0.10]git checkout -b my-new-feature)git commit -am 'Added some feature')git push origin my-new-feature)Copyright 2012 Jon Buda. This is free software, and may be redistributed under the terms specified in the LICENSE file.
No open issues yet, or sync has not completed.