Interactions
WebGL shaderFree

Image Compare

A hardware-accelerated image comparison slider featuring 8x8 Bayer ordered dithering, customizable multi-tone palettes, seam dissolving, and interactive wobbling spring physics.

Full-page view

Live preview

Interact with the effect here. Drag, hover, and use its controls.

Ordered-dithered comparison image. Original comparison image.

Variation Tweaking

Adjust the options and see the preview update live.

Color palette
Line color
3
1
56
1.25
0.02
1
0.6

Installation

Install automatically via CLI or manually integrate dependencies and code.

$npx @istmx/ui add image-compare

Usage

Import the component and configure visual variants, sizes, and operational states.

import { ImageCompare } from '@/components/ui/image-compare'
 
{/* Rich 4-tone ordered dither (default) */}
<ImageCompare />
 
{/* Hard 1-bit, Game Boy Camera energy */}
<ImageCompare palette={['#09090b', '#fafafa']} pixelSize={4} sharpen={0.9} />
 
{/* Warm duotone-ish ramp */}
<ImageCompare palette={['#120b08', '#5a2e1d', '#c9803e', '#fff1d6']} />
 
{/* Hard cut, no dissolve */}
<ImageCompare blendWidth={0} />

Composition

Compose with icons, form triggers, and layout containers.

<div className="aspect-[4/3] w-full max-w-2xl overflow-hidden rounded-3xl border border-border">
<ImageCompare
beforeSrc="/cj1.jpg"
afterSrc="/cj1.jpg"
beforeLabel="Bayer Dither"
afterLabel="Original"
pixelSize={3}
wobble
wobbliness={1}
/>
</div>

API Reference

Property matrix, types, defaults, and usage descriptions.

PropTypeDefaultDescription
beforeSrc / afterSrcstring'/cj1.jpg'Source URLs for the before (dithered) and after (original) images.
palettestring[]['#09090b', '#34343d', '#8e8e9b', '#fafafa']Color hex or rgb strings defining the dither ramp tones.
ditherLevelsnumberundefinedOptional step count to automatically generate an evenly distributed ramp.
pixelSizenumber3Size of individual dither cells in device-independent pixels.
contrast / brightnessnumber / number1.25 / 0.02Luminance contrast multiplier and brightness offset.
gamma / sharpennumber / number1 / 0.6Gamma power curve and pre-quantization sharpening intensity.
blendWidthnumber56Width in pixels of the ordered-dither dissolve transition across the seam.
wobble / wobblinessboolean / numbertrue / 1Toggle spring divider bending and set the wobble intensity multiplier.
lineWidth / lineColornumber / string1.5 / 'rgba(255, 255, 255, 0.95)'Divider stroke width and color.
showHandle / handleSizeboolean / numbertrue / 40Toggle circular drag handle and specify its diameter.
showLabelsbooleantrueToggle before and after text label badges in the corners.
disabledbooleanfalseDisable user drag and keyboard interactions.
onPositionChange(position: number) => voidundefinedCallback fired during active drag movements with the divider percentage.

Data Attributes

State-reflecting DOM attributes for custom selector styling.

This component does not expose custom data attributes. Standard HTML data attributes are forwarded to its interactive element.

How It Works

A WebGL fragment shader quantizes incoming pixels against an 8x8 Bayer threshold matrix mapped into a custom palette texture. Dragging or sweeping the divider calculates velocity vectors to drive a damped spring simulation, bending the divider dynamically in real-time.

Accessibility

The slider container exposes an ARIA slider role with full keyboard support (Arrow keys, Home, End), screen reader position announcements, and graceful fallback for systems with reduced motion.

Keyboard Navigation
Arrow Left / DownStep the slider 2% to the left.
Arrow Right / UpStep the slider 2% to the right.
Shift + ArrowsStep the slider 10% in either direction.
Home / EndJump divider directly to 0% or 100%.

Limitations

•Hardware WebGL 1/2 is required for real-time shader dithering; browsers without WebGL gracefully fall back to image clipping.
•Cross-origin images must be served with appropriate CORS headers to allow WebGL texture uploads.

Features

•Hardware-accelerated 8x8 Bayer ordered dithering.
•Multi-tone customizable palette ramps (2-16 tones).
•Configurable dissolve width across the comparison seam.
•Interactive spring-physics divider with responsive wobble and bending.
•Full ARIA accessibility, touch gesture support, and keyboard controls.
Credits

Meet the team behind the interaction

Crafted for modern web applications and AI agent workflows.

Aryan

Aryan

@istmX

Building high-performance interfaces, developer tooling, and autonomous agent workflows.

Helped by
Ella

Ella

UI/UX Designer

Crafting beautiful experiences.

Kenji

Kenji

WebGL & Shader Designer

Bringing visuals to life.

Sarah

Sarah

Motion Designer

Animating the details.