The identicon package

[ Tags: bsd3, graphics, image, library ] [ Propose Tags ]

Flexible generation of identicons.

[Skip to Readme]


Versions 0.1.0, 0.2.0, 0.2.1, 0.2.2
Change log
Dependencies base (>=4.7 && <5.0), bytestring (>=0.10.6 && <0.13), JuicyPixels (>= && <4.0), semigroups (==0.18.*) [details]
License BSD3
Author Mark Karpov <>
Maintainer Mark Karpov <>
Category Graphics, Image
Home page
Bug tracker
Source repo head: git clone
Uploaded Mon May 22 16:12:43 UTC 2017 by mrkkrp
Updated Fri Jan 12 06:05:29 UTC 2018 by mrkkrp to revision 2   [What is this?]
Distributions LTSHaskell:0.2.2, NixOS:0.2.2, Stackage:0.2.2, openSUSE:0.2.2
Downloads 950 total (28 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-05-22 [all 1 reports]
Hackage Matrix CI





Turn on development settings.


Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info


Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

For package maintainers and hackage trustees

Readme for identicon-0.2.2

[back to package description]


License BSD3 Hackage Stackage Nightly Stackage LTS Build Status Coverage Status

The package implements a flexible framework for identicons generation on top of the Juicy Pixels package.

Quick start

To use the package you usually need the following set of imports (and a couple of language extensions for the type level magic):

{-# LANGUAGE DataKinds     #-}
{-# LANGUAGE TypeOperators #-}

import Codec.Picture -- JuicyPixels
import Data.ByteString (ByteString) -- we use strict byte strings
import Data.Proxy
import Data.Word (Word8)
import Graphics.Identicon -- core definitions
import Graphics.Identicon.Primitive -- some visual primitives

You first write a type that holds information about total number of bytes your identicon consumes and number of distinct visual components it has (they are called “layers” in the terminology of the package):

type MyIcon = Identicon 12 :+ Consumer 4 :+ Consumer 4 :+ Consumer 4

Here we have an identicon that needs 12 bytes to be generated. It has three consumers that take 4 bytes each and generate layers, i.e. visual objects (circles, squares, etc.).

The second step is to write implementation of every layer. We can use the primitives available out-of-the-box, they live in the Graphics.Identicon.Primitive module:

myImpl :: Implementation MyIcon
myImpl = Identicon :+ a :+ a :+ a
    a :: Word8 -> Word8 -> Word8 -> Word8 -> Layer
    a r g b n = rsym $ onGrid 3 3 n $
      gradientXY (edge . mid) black (PixelRGB8 r g b)

We could choose to code every layer differently, but since position and color of every layer are unlikely to be the same, this approach will work well too.

Every byte is available to the layer-generating function as a distinct Word8 argument. The type system makes sure that:

  • you consume exactly as many bytes as you promised in type of your identicon;

  • you have as many layers as you described in type of your identicon;

  • every function in your implementation has a correct signature (i.e. it grabs as many Word8s as promised and produces a Layer in the end).

Mixing of layers and generation is handled by the library like this:

-- | Here is the function that generates your identicons. It's usually
-- convenient to wrap the 'renderIdenticon' function that comes with the
-- library.

  :: Int               -- ^ Identicon width
  -> Int               -- ^ Identicon height
  -> ByteString        -- ^ Input (some sort of hash or something)
  -> Maybe (Image PixelRGB8)
     -- ^ Identicon, unless 'ByteString' is too short
genMyIdenticon = renderIdenticon (Proxy :: Proxy MyIcon) myImpl

For more information head straight to the Haddocks. BTW, I have written a blog post about the package where I demonstrate some pictures generated with it.


Copyright © 2016–2017 Mark Karpov

Distributed under BSD 3 clause license.