Shaders / Examples / Image

Image

A picture or a capture, redrawn in five greys and the ember.

Drawn with
Canvas 2D
Chain
image → pixelate → image-dither → palette
Code
@forgeron/shaders: builtInPresets()["role-image"]
/01 → What it is
  • Luminance through the 4×4 Bayer matrix to five greys; the ember only where the picture is warm.
  • Cropped to cover the canvas, one dithered pixel per 3 CSS pixels: whatever made the picture, it comes out in the system.
/02 → Where Forgeron uses it
SiteWhereSettings
forgeron.shLanding exploration D, the hero picture (not on a live page today)canvas[data-dither-img="/lab/hero-forge.png"] data-px="3"
/03 → Versions
  • /01 Heropixel 3 · gain 1.1
  • /02 Sourcethe picture, before
  • /03 Coarsepixel 5
/04 → Use it
/01 → React
import { DitheredImage } from "@forgeron/ui";

<div style={{ height: 320 }}>
  <DitheredImage src="/hero.png" pixel={3} />
</div>
/02 → Plain DOM
import { mountDitheredImage } from "@forgeron/ui";

mountDitheredImage(canvas, "/hero.png", { pixel: 3, gain: 1.1 });
/03 → Preset "role-image" (builtInPresets())
{
  "$schema": "https://shaders.forgeron.sh/schema/preset.v1.json",
  "version": 1,
  "name": "role-image",
  "source": {
    "type": "image"
  },
  "passes": [
    {
      "type": "pixelate",
      "size": 3
    },
    {
      "type": "image-dither",
      "gain": 1.1,
      "greys": 5
    },
    {
      "type": "palette",
      "tones": [
        {
          "var": "--bg",
          "fallback": "#0a0a0a"
        },
        {
          "var": "--line-strong",
          "fallback": "#2e2e2e"
        },
        {
          "var": "--ink-dim",
          "fallback": "#5e5e5e"
        },
        {
          "var": "--ink-muted",
          "fallback": "#8f8f8f"
        },
        {
          "var": "--ink",
          "fallback": "#ededed"
        },
        {
          "var": "--accent",
          "fallback": "#ff4f1f"
        }
      ],
      "transparent": []
    }
  ]
}
API → Options
OptionTypeDefaultDescription
srcstring—The picture. On a load error the canvas hides itself.
pixelnumber3Side of one dithered pixel in CSS pixels.
gainnumber1.1Luminance gain before dithering.