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
| Mode | Rendering Mechanism | Best Use Case | Localization / Labels |
|---|---|---|---|
| Before / After | Side-by-side canvas with 12% top header bar | Product retouching, UI redesigns, restoration | 11 built-in languages (EN, UK, ES, DE, FR, PT, ZH, JA, KO, HI, AR) |
| Interactive Split Slider | CSS clip-path live curtain + clipped HD canvas export | Pixel-aligned grading, 3D renders, compression diffs | Localized corner pills + draggable handle |
| VS Badge | Side-by-side canvas with centered circular badge | Head-to-head product, camera, or model comparisons | Centered high-contrast VS emblem |
| Now / Then | Side-by-side canvas with top header bar | Historical progression, timeline comparisons | NOW / THEN header labels |
| Custom Labels | Side-by-side canvas with user-defined header text | Benchmarking (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.createObjectURLare 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.
Related Tools
Related Posts
Learn how to create, style, and decode 1D barcodes and 2D codes in Python. Master python-barcode, Pillow rendering options (including removing label text), pyzbar, and OpenCV decoding.
You can check the history of a specific line in VS Code using the built-in features or the specific view. You can also install the free extension.
A comprehensive guide to working with QR codes in Python. Learn how to generate custom QR codes, embed brand logos, decode images, parse vectors (SVG), handle video arrays, and host online links.


