Skip to main content

Image Comparison Slider Creator

Build high-resolution side-by-side Before/After banners, VS composites, and interactive split-screen sliders directly in your browser with instant PNG export and zero cloud uploads.


Technical Architecture: Reverse-Engineering Interactive Image Comparison​

Before-and-after visual comparison tools allow creators and engineers to inspect subtle differences between two images (such as color grading, photo restoration, 3D renders, UI redesigns, or compression artifacts) and export publication-ready composites.

1. Dynamic CSS Polygon Masking & Pointer Normalization​

In Interactive Split Slider mode, rather than re-encoding canvas frames on every pointer move, the live viewport uses hardware-accelerated CSS clip-path masks. Two aligned image layers are stacked, and the top layer is clipped dynamically:

const updateSliderFromClientX = useCallback((clientX) => {
const container = sliderContainerRef.current;
if (!container) return;
const rect = container.getBoundingClientRect();
if (!rect.width) return;

// Clamp split ratio between 0% and 100%
const pct = Math.max(0, Math.min(100, ((clientX - rect.left) / rect.width) * 100));
setSliderPos(Math.round(pct));
}, []);

The top overlay applies clip-path: polygon(0 0, ${sliderPos}% 0, ${sliderPos}% 100%, 0 100%) while the container sets touch-action: pan-y and binds the Pointer Events API (onPointerDown, onPointerMove, setPointerCapture). This keeps horizontal dragging locked at 60fps on mobile touch screens while preserving vertical page scrolling, paired with a synchronized <input type="range"> for keyboard navigation.

2. High-Resolution Canvas Compositing & Height Normalization​

When combining two images with different aspect ratios or resolutions (for example, a portrait photo next to a landscape photo), naive concatenation leaves empty voids or distorts proportions. The compositing engine normalizes both assets to a shared targetHeight capped at 1440px so exported PNGs stay sharp on Retina and 4K displays:

const targetHeight = Math.min(img1.naturalHeight, img2.naturalHeight, MAX_EXPORT_HEIGHT);
const w1 = Math.round(img1.naturalWidth * (targetHeight / img1.naturalHeight));
const w2 = Math.round(img2.naturalWidth * (targetHeight / img2.naturalHeight));

if (currentMode.style === 'slider') {
ctx.drawImage(img2, 0, 0, w1, targetHeight);
const splitX = Math.round((sliderPos / 100) * w1);
ctx.save();
ctx.beginPath();
ctx.rect(0, 0, splitX, targetHeight);
ctx.clip();
ctx.drawImage(img1, 0, 0, w1, targetHeight);
ctx.restore();
}

3. Asynchronous canvas.toBlob Pipeline & iOS Safari Download Reliability​

Calling canvas.toDataURL('image/png') synchronously on large canvases blocks the main thread and generates multi-megabyte Base64 data: strings that frequently fail or re-trigger download prompts on iOS Safari (WebKit).

Instead, ImageComparisonCreator encodes a binary Blob asynchronously via canvas.toBlob() whenever a draw pass completes and binds a persistent Object URL directly to a native <a download> anchor and the Web Share API (navigator.share):

canvas.toBlob((blob) => {
if (isCancelled || !blob) return;
const fileName = `image-comparison-${Date.now()}.png`;
const file = new File([blob], fileName, { type: 'image/png' });
const url = URL.createObjectURL(blob);

if (activeExportUrlRef.current) {
// Delay revocation by 60s so iOS Safari's async download sheet can read the Blob
scheduleUrlRevoke(activeExportUrlRef.current);
}
activeExportUrlRef.current = url;
setExportData({ url, file, fileName, sizeKb: Math.max(1, Math.round(blob.size / 1024)) });
}, 'image/png');

Comparison Modes & Display Specifications​

ModeRendering MechanismBest Use CaseLocalization / Labels
Before / AfterSide-by-side canvas with 12% top header barProduct retouching, UI redesigns, restoration11 built-in languages (EN, UK, ES, DE, FR, PT, ZH, JA, KO, HI, AR)
Interactive Split SliderCSS clip-path live curtain + clipped HD canvas exportPixel-aligned grading, 3D renders, compression diffsLocalized corner pills + draggable handle
VS BadgeSide-by-side canvas with centered circular badgeHead-to-head product, camera, or model comparisonsCentered high-contrast VS emblem
Now / ThenSide-by-side canvas with top header barHistorical progression, timeline comparisonsNOW / THEN header labels
Custom LabelsSide-by-side canvas with user-defined header textBenchmarking (v1.0 vs v2.0, RAW vs WebP)Custom left and right strings (up to 24 chars)

Client-Side Security & Zero-Server Data Isolation​

  • 100% In-Browser Execution: Images loaded into the creator never leave your device. All decoding, height normalization, and canvas compositing take place within client RAM.
  • Confidential Asset Protection: Ideal for comparing unreleased product mockups, proprietary CAD renderings, medical scans, or private photography without cloud privacy exposure.
  • Deferred Heap Reclamation: Object URLs generated via URL.createObjectURL are retained while active for iOS Safari compatibility and automatically revoked after replacement or component unmount to prevent memory leaks.

Get notified about updates to this tool

No spam. Just high-quality updates about new features and guides.