Class IdenticonRenderer

java.lang.Object
network.ike.docs.koncept.IdenticonRenderer

public final class IdenticonRenderer extends Object
Renders the Komet identicon for a koncept as a PNG.

The image is byte-identical to the one Komet draws (dev.ikm.komet.framework.Identicon) because it uses the same library (com.sparrowwallet:toucan), the same algorithm version (LifeHashVersion.VERSION2), and the same input string (the Tinkar idString produced by KonceptIdentity). LifeHash is a deterministic visual hash: the SHA-256 of the UTF-8 input drives a cellular-automaton render whose pattern depends only on the input and the version — moduleSize merely scales pixel density (nearest neighbour), never the pattern.

VERSION2 produces a 32×32 native grid; at DISPLAY_MODULE_SIZE that is the 128×128 Komet renders at. Two output forms are provided:

  • dataUri(String) — a base64 data: URI for inline HTML (html5 and CSS-PDF backends).
  • pngFile(String) — a PNG written to a content-addressed file, for backends that need a file reference (DocBook→FO, Prawn PDF).
Both are memoized by idString.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Module size for displayed identicons.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    dataUri(String idString)
    Renders the identicon for an idString as a base64 data:image/png URI suitable for an inline HTML <img src>.
    static byte[]
    png(String idString, int moduleSize)
    Renders the identicon for an idString as PNG bytes.
    static String
    pngFile(String idString)
    Writes the identicon for an idString to a content-addressed PNG file and returns its absolute path.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DISPLAY_MODULE_SIZE

      public static final int DISPLAY_MODULE_SIZE
      Module size for displayed identicons. VERSION2's 32×32 native grid × 4 = 128×128, matching Komet's displayed size.
      See Also:
  • Method Details

    • png

      public static byte[] png(String idString, int moduleSize)
      Renders the identicon for an idString as PNG bytes.
      Parameters:
      idString - the Tinkar idString (LifeHash input)
      moduleSize - the per-cell pixel size (must be > 0); the output is 32 * moduleSize square for VERSION2
      Returns:
      the PNG-encoded identicon
      Throws:
      UncheckedIOException - if PNG encoding fails
    • dataUri

      public static String dataUri(String idString)
      Renders the identicon for an idString as a base64 data:image/png URI suitable for an inline HTML <img src>. Memoized per idString.
      Parameters:
      idString - the Tinkar idString (LifeHash input)
      Returns:
      a data:image/png;base64,… URI
      Throws:
      UncheckedIOException - if PNG encoding fails
    • pngFile

      public static String pngFile(String idString)
      Writes the identicon for an idString to a content-addressed PNG file and returns its absolute path. Backends that cannot embed a data: URI (DocBook→FO via FOP/XEP, Prawn PDF) reference the file directly; with SafeMode.UNSAFE (used by the doc pipeline) absolute image paths resolve in all of them. The filename is derived from a hash of the idString, so identical concepts share one file and re-runs are stable. Memoized per idString.
      Parameters:
      idString - the Tinkar idString (LifeHash input)
      Returns:
      the absolute filesystem path of the written PNG
      Throws:
      UncheckedIOException - if the file cannot be written