Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

miro

> 编程语言
Open source

A Ruby gem to help extract the dominant colors from an image.

557 stars0 likes0 views
WebsiteGitHub

About

A Ruby gem to help extract the dominant colors from an image.

Miro

Extract the dominant colors from an image.

Feedback

Questions, Comments, Concerns, or Bugs?

GitHub Issues For All!

Installation

Add this line to your application's Gemfile:

gem 'miro'

And then execute:

$ bundle

Or install it yourself as:

$ gem install miro

Usage

Configuration

ruby
# 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

ruby
# 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

ruby
# 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

ruby
# 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]

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

Copyright 2012 Jon Buda. This is free software, and may be redistributed under the terms specified in the LICENSE file.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言