identicon
Version, currently master branch1 version
- master branchlatestMay 21, 2020
github.com/watzon/identicon
Pure Crystal identicon generator
Installation
# Add this to your shard.yml
dependencies:
identicon:
github: watzon/identicon
branch: mastermaster is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
0.34.0- License
- MIT
- Author
- Chris Watson
Dependencies
Runtime Dependencies
- stumpy_png~> 4.5github: stumpycr/stumpy_png
- stumpy_utils*github: watzon/stumpy_utils, branch: master
README
identicon.cr
A Crystal implementation of ruby_identicon which is a Ruby implementation of go-identicon.
identicon.cr creates an identicon, similar to those created by Github. Unfortunately the algorithm Github uses isn't open source, so this isn't the exact same.
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 the dependency to your
shard.yml:dependencies: identicon: github: watzon/identicon -
Run
shards install
Usage
First require the library:
require "identicon"
You can easily generate and save a png identicon:
Identicon.create_and_save("myemailaddress@gmail.com", "sample_01.png")
Which creates an identicon that looks like this:
![]()
If you don't want to save a file, you can also generate an IO:
Identicon.create("myemailaddress@gmail.com")
This returns an IO::Memory containing the raw PNG bytes. If you wish to export a base64 encoded string you can do that too:
Identicon.create_base64("myemailaddress@gmail.com")
Options
All of the create methods take a number of different options that can be used to change the appearance of the generated image. The options are:
key
A 16 byte key to be passed to the siphash digest.
grid_size
The number of rows and columns in the identicon. A Github identicon is 5x5, but we default to 7x7.
border_size
The size in pixels to leave as an empty border around the identicon image. Defaults to 35.
square_size
The size in pixels of each square that makes up the identicon. Defaults to 50.
background_color
The StumpyPNG::RGBA color to use as the image background.
bit_depth
The bit depth of the generated image. Defaults to 8.
color_type
The color type of the generated image. Defaults to :rgb_alpha.
Contributing
- Fork it (https://github.com/watzon/identicon/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Chris Watson - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
master- Seen
- May 21, 2020
- Crystal
0.34.0- Indexed
- yes
Dependents
Repository
github.com/watzon/identicon
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 14, 2026
- Synced
- Aug 14, 2026
- Versions
- 1