Identikon
A small framework for generating identicons.
(require identikon) | package: identikon |
1 Installation & updates
raco pkg install identikon |
raco pkg update identikon |
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
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.
> (identikon 300 300 "racket")
Create a 300x300 identicon for "racket" using the "squares.rkt" rule module.
> (identikon 300 300 "racket" 'squares)
procedure
(save-identikon filename type image [ #:quality number?]) → boolean? filename : string? type : (or/c symbol? string?) image : image? number? : natural-number/c = 75
#: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
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
width : exact-positive-integer? height : exact-positive-integer? user : (listof exact-positive-integer?)
> (draw-rules 200 200 '(27 180 200 176 189 77 68 156 1 211 209 117 218 72 146 38 144 184 241 76))
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.