Identikon
1 Installation & updates
2 Generating identicons
identikon
save-identikon
identikon->string
3 Rules modules
draw-rules
4 License & source code
6.12

Identikon

Darren Newton <[email protected]>

A small framework for generating identicons.

 (require identikon) package: identikon

1 Installation & updates

At the command line:

raco pkg install identikon

After that, you can update the package from the command line:

raco pkg update identikon

Identikon has a full command line interface which you can view with

raco identikon --help

2 Generating identicons

procedure

(identikon width    
  height    
  input    
  [rules    
  #:filename boolean?])  image?
  width : exact-positive-integer?
  height : exact-positive-integer?
  input : (or/c symbol? string?)
  rules : (or/c symbol? string?) = "default"
  boolean? : #t = #f
Identikon provides a single function, identikon, which produces images based on input. If input is a string or symbole, a SHA1 hash will be produced and used to geneate an image. If a filename is provided a SHA1 of the file will be produced and used as input for generating images.

Produces an identikon with dimensions specified by width and height.

input is converted into a list of numbers based on a SHA1 hash and passed to a rules module for processing into an image?.

rules is the name of the rules module to use in generating the identicon. This defaults to "default".

If #:filename is #t then identikon will treat the value of input as a filename and attempt fo open it for processing.

Examples:

Create a 300x300px identicon for "racket" using the "default.rkt" rule module.

Example:
> (identikon 300 300 "racket")

image

Create a 300x300 identicon for "racket" using the "squares.rkt" rule module.

Example:
> (identikon 300 300 "racket" 'squares)

image

procedure

(save-identikon filename    
  type    
  image    
  [#:quality number?])  boolean?
  filename : string?
  type : (or/c symbol? string?)
  image : image?
  number? : natural-number/c = 75
Save an identikon image to disk. Available types are svg, png and jpeg. If the file already exists, a new version of the file will be saved with a timestamp (seconds) appended.

#:quality only affects jpeg images.

(save-identikon "foo" 'png
                (identikon 300 300 'racket 'qbert))

procedure

(identikon->string type    
  image    
  [#:quality number?])  string?
  type : (or/c symbol? string?)
  image : image?
  number? : natural-number/c = 75
Return an identikon in a string format. This is useful if you want to inject the image directly into an HTML page as an <svg /> element or as a data-uri.

Available types are svg, png and jpeg.

svg will emit a well formed SVG element.

png and jpeg types will emit a string of base-64 encoded bytes suitable for use in an HTML data-uri.

#:quality only affects jpeg images.

(identikon->string (identikon 300 300 'racket 'qbert) 'svg)

3 Rules modules

All rules modules must provide a single draw-rules function and live in the rules folder.

procedure

(draw-rules width height user)  image?

  width : exact-positive-integer?
  height : exact-positive-integer?
  user : (listof exact-positive-integer?)

Example:
> (draw-rules
   200
   200
   '(27 180 200 176 189 77 68 156 1 211 209 117 218 72 146 38 144 184 241 76))

image

4 License & source code

This module is under the MIT license.

Source repository at https://github.com/DarrenN/identikon. Suggestions, corrections and pull-requests welcome.