百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

miro

> 编程语言
开源

一个 Ruby 插件,可帮助从图像中提取主色调。

557 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个 Ruby 插件,可帮助从图像中提取主色调。

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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

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