image dithering

A dithering image filter with four algorithms, custom palettes up to seven colors, and a sampled-from-image mode for retro-photo treatments.

Preview

live
Click the preview to load a random sample image.

Install

npm
npm i @devmischief/shaders-svelte

Code

import { ImageDithering } from '@devmischief/shaders-svelte';

<ImageDithering
  width={1280}
  height={720}
  image="/assets/flowers.webp"
  colorBack="#000c38"
  colorFront="#94ffaf"
  colorHighlight="#eaff94"
  originalColors={false}
  inverted={false}
  type="8x8"
  size={2}
  colorSteps={2}
  scale={1}
  rotation={0}
  offsetX={0}
  offsetY={0}
  fit="cover"
/>
			
			

Shader Props

10
namedescriptiontypevalues
imageSource image processed by the dithering filter.stringurl
colorBackBackground color of the dither palette.stringhex / rgba
colorFrontForeground color of the dither palette.stringhex / rgb
colorHighlightSecondary foreground color (set equal to colorFront for classic 2-color dithering).stringhex / rgb
originalColorsSample the image's own colors instead of the configured palette.booleantrue · false
invertedInvert the image's luminance. Has no effect at zero contrast.booleantrue · false
typeDithering algorithm.stringrandom · 2x2 · 4x4 · 8x8
sizePixel size of the dithering grid.number0.5 → 20
colorStepsNumber of colors in the palette.number1 → 7
fitHow the source image is fit into the canvas.stringcover · contain

Common Props

9
namedescriptiontypevalues
scaleOverall zoom level of the graphics.number0.01 → 4
rotationOverall rotation angle of the graphics.number0 → 360
offsetXHorizontal offset of the graphics.number−1 → 1
offsetYVertical offset of the graphics.number−1 → 1
originXReference point for positioning width in the canvas.number0 → 1
originYReference point for positioning height in the canvas.number0 → 1
speedAnimation speed for time-based motion.number
minPixelRatioMinimum pixel ratio used when rendering the shader (default 2).number
maxPixelCountMaximum pixel count the shader may process.number

built with mischief by devmischief

@devmischief/shaders-svelte