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

ruby_identicon

> 编程语言
开源

一个用于创建类似 GitHub 的标识图标的 Ruby 插件

290 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个用于创建类似 GitHub 的标识图标的 Ruby 插件

RubyIdenticon

A Ruby implementation of go-identicon by Damian Gryski

RubyIdenticon creates an identicon, similar to those created by Github.

A title and key are used by siphash to calculate a hash value that is then used to create a visual identicon representation. The identicon is made by creating a left hand side pixel representation of each bit in the hash value - this is then mirrored onto the right hand side to create an image that we see as a shape. The grid and square sizes can be varied to create identicons of differing size.

Installation

Add this line to your application's Gemfile:

gem 'ruby_identicon'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ruby_identicon

Usage

Creating an identicon and saving to png

ruby
RubyIdenticon.create_and_save("RubyIdenticon", "ruby_identicon.png")

Creating an identicon and returning a binary string

ruby
blob = RubyIdenticon.create("RubyIdenticon")

# optional, save to a file
File.open("ruby_identicon.png", "wb") do |f| f.write(blob) end

Creating an identicon and returns in base64 format

ruby
base64_identicon = RubyIdenticon.create_base64("RubyIdenticon")

nb// to render this in html pass the base64 code into your view

ruby
raw ""

Customising the identicon

The identicon can be customised by passing additional options

background_color:  (Integer, default 0) the background color of the identicon in rgba notation (e.g. 0xffffffff for white)
border_size:  (Integer, default 35) the size in pixels to leave as an empty border around the identicon image
grid_size:    (Integer, default 7)  the number of rows and columns in the identicon, minimum 4, maximum 9
square_size:  (Integer, default 50) the size in pixels of each square that makes up the identicon
key:          (String) a 16 byte key used by siphash when calculating the hash value (see note below)

Varying the key ensures uniqueness of an identicon for a given title, it is assumed desirable for different applications
to use a different key.

Example

ruby
blob = RubyIdenticon.create("identicons are great!", grid_size: 5, square_size: 70, background_color: 0xf0f0f0ff, key: "1234567890123456")
File.open("tmp/test_identicon.png", "wb") do |f| f.write(blob) end

Contributing

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

Issues· 0 开放

查看全部 Issues在 GitHub 打开

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

> 标签

Ruby

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

> 工具信息

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

> 相关工具

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