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

ruby_identicon

> 编程语言
Open source

A Ruby gem for creating Github like identicons

290 stars0 likes1 views
WebsiteGitHub

About

A Ruby gem for creating Github like identicons

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 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 18, 2026
Category编程语言
PricingOpen source

> Related tools

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