The user wants an image processing pipeline with multiple filters. This is a great opportunity to create an interactive tool where users can:
- Load an image (upload or default)
- Apply various filters to it
- See results in real-time
- Chain multiple filters together
I'll create a visually striking, professional image processing tool with:
- A dark, technical/industrial aesthetic (since it's a "processing" tool)
- Multiple filter options (brightness, contrast, saturation, blur, sharpen, grayscale, sepia, invert, vignette, etc.)
- Real-time preview
- Filter stack/pipeline visualization
- Before/after comparison
- Export functionality
Design decisions:
- Font: Space Grotesk (technical) + JetBrains Mono (for values/labels)
- Color scheme: Dark with cyan/electric blue accent (technical feel)
- Background: Subtle grid pattern with glow effects
- Layout: Side panel for filters, main area for preview
Filters to implement using Canvas API:
- Brightness
- Contrast
- Saturation
- Blur
- Sharpen (convolution kernel)
- Grayscale
- Sepia
- Invert
- Vignette
- Noise/Grain
- Edge detection (Sobel)
- Emboss
I'll make the pipeline visual so users can see the stack of filters being applied.
Image Processing Pipeline
A professional, interactive image filtering tool with a real-time pipeline visualization. Features multiple filters that can be stacked and adjusted dynamically.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Processing Pipeline</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&family=Space+Grotesk:wght@400;500;700&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0a0e14;
--bg-secondary: #111820;
--fg: #e6e6e6;
--muted: #5c6773;
--accent: #00e5c7;
--accent-dim: rgba(0, 229, 199, 0.15);
--card: #161d26;
--border: #2a3441;
--danger: #ff6b6b;
--warning: #ffd93d;
}
* {
box-sizing: border-box;
}
body {
font-family: 'Space Grotesk', sans-serif;
background: var(--bg);
color: var(--fg);
min-height: 100vh;
}
.mono {
font-family: 'JetBrains Mono', monospace;
}
.bg-grid {
background-image:
linear-gradient(rgba(0, 229, 199, 0.03) 1px, transparent 1px),
linear-gradient(90deg, rgba(0, 229, 199, 0.03) 1px, transparent 1px);
background-size: 32px 32px;
}
.glow-line {
position: absolute;
height: 1px;
background: linear-gradient(90deg, transparent, var(--accent), transparent);
animation: glow-pulse 3s ease-in-out infinite;
}
@keyframes glow-pulse {
0%, 100% { opacity: 0.3; }
50% { opacity: 0.8; }
}
.filter-card {
background: var(--card);
border: 1px solid var(--border);
transition: all 0.2s ease;
}
.filter-card:hover {
border-color: var(--accent);
box-shadow: 0 0 20px rgba(0, 229, 199, 0.1);
}
.filter-card.active {
border-color: var(--accent);
background: linear-gradient(135deg, var(--card), rgba(0, 229, 199, 0.05));
}
.pipeline-node {
position: relative;
}
.pipeline-node::after {
content: '';
position: absolute;
right: -24px;
top: 50%;
width: 24px;
height: 2px;
background: var(--border);
}
.pipeline-node:last-child::after {
display: none;
}
.slider-track {
-webkit-appearance: none;
appearance: none;
width: 100%;
height: 4px;
background: var(--border);
border-radius: 2px;
outline: none;
}
.slider-track::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 16px;
height: 16px;
border-radius: 50%;
background: var(--accent);
cursor: pointer;
transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.slider-track::-webkit-slider-thumb:hover {
transform: scale(1.2);
box-shadow: 0 0 12px var(--accent);
}
.slider-track::-moz-range-thumb {
width: 16px;
height: 16px;
border-radius: 50%;
background: var(--accent);
cursor: pointer;
border: none;
}
.btn-primary {
background: var(--accent);
color: var(--bg);
font-weight: 600;
transition: all 0.2s ease;
}
.btn-primary:hover {
box-shadow: 0 0 24px rgba(0, 229, 199, 0.4);
transform: translateY(-1px);
}
.btn-secondary {
background: transparent;
border: 1px solid var(--border);
color: var(--fg);
transition: all 0.2s ease;
}
.btn-secondary:hover {
border-color: var(--accent);
color: var(--accent);
}
.canvas-container {
position: relative;
background: var(--bg-secondary);
border: 1px solid var(--border);
border-radius: 12px;
overflow: hidden;
}
.canvas-container::before {
content: '';
position: absolute;
inset: 0;
background:
linear-gradient(45deg, transparent 48%, var(--border) 49%, var(--border) 51%, transparent 52%),
linear-gradient(-45deg, transparent 48%, var(--border) 49%, var(--border) 51%, transparent 52%);
background-size: 16px 16px;
opacity: 0.3;
pointer-events: none;
}
.comparison-slider {
position: absolute;
top: 0;
bottom: 0;
width: 4px;
background: var(--accent);
cursor: ew-resize;
z-index: 10;
}
.comparison-slider::before {
content: '';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 32px;
height: 32px;
background: var(--accent);
border-radius: 50%;
box-shadow: 0 0 16px var(--accent);
}
.comparison-slider::after {
content: '⟷';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: var(--bg);
font-weight: bold;
font-size: 14px;
}
.fade-in {
animation: fadeIn 0.4s ease forwards;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.stagger-1 { animation-delay: 0.1s; }
.stagger-2 { animation-delay: 0.2s; }
.stagger-3 { animation-delay: 0.3s; }
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
}
}
.drop-zone {
border: 2px dashed var(--border);
transition: all 0.3s ease;
}
.drop-zone.drag-over {
border-color: var(--accent);
background: rgba(0, 229, 199, 0.05);
}
.processing-indicator {
position: absolute;
top: 12px;
right: 12px;
padding: 6px 12px;
background: rgba(0, 0, 0, 0.7);
border-radius: 6px;
font-size: 12px;
display: flex;
align-items: center;
gap: 8px;
opacity: 0;
transition: opacity 0.2s ease;
}
.processing-indicator.active {
opacity: 1;
}
.spinner {
width: 14px;
height: 14px;
border: 2px solid var(--muted);
border-top-color: var(--accent);
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.tooltip {
position: relative;
}
.tooltip::before {
content: attr(data-tooltip);
position: absolute;
bottom: 100%;
left: 50%;
transform: translateX(-50%);
padding: 6px 10px;
background: var(--fg);
color: var(--bg);
font-size: 12px;
border-radius: 4px;
white-space: nowrap;
opacity: 0;
pointer-events: none;
transition: opacity 0.2s ease;
}
.tooltip:hover::before {
opacity: 1;
}
</style>
</head>
<body class="bg-grid">
<div class="glow-line" style="top: 0; left: 0; right: 0;"></div>
<div class="min-h-screen p-4 md:p-6 lg:p-8">
<!-- Header -->
<header class="mb-8 fade-in">
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
<div>
<h1 class="text-2xl md:text-3xl font-bold tracking-tight" style="color: var(--fg);">
Image Processing Pipeline
</h1>
<p class="text-sm mt-1" style="color: var(--muted);">
Stack multiple filters and process in real-time
</p>
</div>
<div class="flex gap-3">
<button id="uploadBtn" class="btn-secondary px-4 py-2 rounded-lg flex items-center gap-2 text-sm">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
Upload Image
</button>
<button id="downloadBtn" class="btn-primary px-4 py-2 rounded-lg flex items-center gap-2 text-sm">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="7 10 12 15 17 10"/>
<line x1="12" y1="15" x2="12" y2="3"/>
</svg>
Export
</button>
</div>
</div>
</header>
<div class="grid lg:grid-cols-[1fr_340px] gap-6">
<!-- Main Canvas Area -->
<div class="space-y-4 fade-in stagger-1">
<div class="canvas-container aspect-video relative" id="canvasContainer">
<canvas id="mainCanvas" class="w-full h-full relative z-[1]"></canvas>
<canvas id="originalCanvas" class="absolute inset-0 w-full h-full z-[2]"></canvas>
<div class="comparison-slider" id="comparisonSlider" style="left: 50%; display: none;"></div>
<div class="processing-indicator" id="processingIndicator">
<div class="spinner"></div>
<span class="mono">Processing...</span>
</div>
<!-- Drop Zone Overlay -->
<div id="dropZone" class="drop-zone absolute inset-0 z-[20] flex items-center justify-center bg-opacity-90" style="background: var(--bg);">
<div class="text-center">
<svg class="mx-auto mb-4" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" style="color: var(--muted);">
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"/>
<circle cx="8.5" cy="8.5" r="1.5"/>
<polyline points="21 15 16 10 5 21"/>
</svg>
<p style="color: var(--muted);">Drop an image here or click Upload</p>
<button id="loadSampleBtn" class="mt-4 btn-secondary px-4 py-2 rounded-lg text-sm">
Load Sample Image
</button>
</div>
</div>
</div>
<!-- Comparison Toggle -->
<div class="flex items-center justify-between p-4 rounded-lg" style="background: var(--card); border: 1px solid var(--border);">
<div class="flex items-center gap-3">
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" id="compareToggle" class="sr-only peer">
<div class="w-10 h-6 rounded-full peer-focus:ring-2 peer-focus:ring-offset-2 transition-colors"
style="background: var(--border); --tw-ring-color: var(--accent); --tw-ring-offset-color: var(--bg);">
<div class="w-4 h-4 rounded-full mt-1 ml-1 transition-transform peer-checked:translate-x-4"
style="background: var(--muted);"></div>
</div>
<span class="text-sm">Compare with Original</span>
</label>
</div>
<button id="resetAllBtn" class="text-sm px-3 py-1.5 rounded-md transition-colors hover:bg-opacity-10"
style="color: var(--danger);">
Reset All Filters
</button>
</div>
<!-- Active Pipeline -->
<div class="p-4 rounded-lg" style="background: var(--card); border: 1px solid var(--border);">
<div class="flex items-center justify-between mb-4">
<h3 class="font-medium text-sm">Active Pipeline</h3>
<span class="mono text-xs px-2 py-1 rounded" style="background: var(--accent-dim); color: var(--accent);" id="filterCount">0 filters</span>
</div>
<div id="pipelineList" class="flex flex-wrap gap-2 min-h-[40px] items-center">
<span class="text-sm" style="color: var(--muted);">No filters applied</span>
</div>
</div>
</div>
<!-- Filters Panel -->
<div class="space-y-3 fade-in stagger-2 overflow-y-auto max-h-[calc(100vh-180px)]" id="filtersPanel">
<div class="sticky top-0 z-10 pb-2" style="background: var(--bg);">
<h2 class="font-medium mb-1">Filters</h2>
<p class="text-xs" style="color: var(--muted);">Click to enable, adjust values</p>
</div>
<!-- Basic Adjustments -->
<div class="space-y-2">
<h3 class="text-xs uppercase tracking-wider mono" style="color: var(--muted);">Basic Adjustments</h3>
<div class="filter-card rounded-lg p-4" data-filter="brightness">
<div class="flex items-center justify-between mb-3">
<span class="text-sm font-medium">Brightness</span>
<span class="mono text-xs px-2 py-0.5 rounded" style="background: var(--bg);" id="brightness-value">0</span>
</div>
<input type="range" class="slider-track" id="brightness" min="-100" max="100" value="0">
</div>
<div class="filter-card rounded-lg p-4" data-filter="contrast">
<div class="flex items-center justify-between mb-3">
<span class="text-sm font-medium">Contrast</span>
<span class="mono text-xs px-2 py-0.5 rounded" style="background: var(--bg);" id="contrast-value">0</span>
</div>
<input type="range" class="slider-track" id="contrast" min="-100" max="100" value="0">
</div>
<div class="filter-card rounded-lg p-4" data-filter="saturation">
<div class="flex items-center justify-between mb-3">
<span class="text-sm font-medium">Saturation</span>
<span class="mono text-xs px-2 py-0.5 rounded" style="background: var(--bg);" id="saturation-value">0</span>
</div>
<input type="range" class="slider-track" id="saturation" min="-100" max="100" value="0">
</div>
<div class="filter-card rounded-lg p-4" data-filter="exposure">
<div class="flex items-center justify-between mb-3">
<span class="text-sm font-medium">Exposure</span>
<span class="mono text-xs px-2 py-0.5 rounded" style="background: var(--bg);" id="exposure-value">0</span>
</div>
<input type="range" class="slider-track" id="exposure" min="-100" max="100" value="0">
</div>
</div>
<!-- Blur & Sharpen -->
<div class="space-y-2">
<h3 class="text-xs uppercase tracking-wider mono" style="color: var(--muted);">Blur & Sharpen</h3>
<div class="filter-card rounded-lg p-4" data-filter="blur">
<div class="flex items-center justify-between mb-3">
<span class="text-sm font-medium">Gaussian Blur</span>
<span class="mono text-xs px-2 py-0.5 rounded" style="background: var(--bg);" id="blur-value">0</span>
</div>
<input type="range" class="slider-track" id="blur" min="0" max="20" value="0">
</div>
<div class="filter-card rounded-lg p-4" data-filter="sharpen">
<div class="flex items-center justify-between mb-3">
<span class="text-sm font-medium">Sharpen</span>
<span class="mono text-xs px-2 py-0.5 rounded" style="background: var(--bg);" id="sharpen-value">0</span>
</div>
<input type="range" class="slider-track" id="sharpen" min="0" max="100" value="0">
</div>
</div>
<!-- Color Effects -->
<div class="space-y-2">
<h3 class="text-xs uppercase tracking-wider mono" style="color: var(--muted);">Color Effects</h3>
<div class="filter-card rounded-lg p-4" data-filter="grayscale">
<div class="flex items-center justify-between mb-3">
<span class="text-sm font-medium">Grayscale</span>
<span class="mono text-xs px-2 py-0.5 rounded" style="background: var(--bg);" id="grayscale-value">0%</span>
</div>
<input type="range" class="slider-track" id="grayscale" min="0" max="100" value="0">
</div>
<div class="filter-card rounded-lg p-4" data-filter="sepia">
<div class="flex items-center justify-between mb-3">
<span class="text-sm font-medium">Sepia</span>
<span class="mono text-xs px-2 py-0.5 rounded" style="background: var(--bg);" id="sepia-value">0%</span>
</div>
<input type="range" class="slider-track" id="sepia" min="0" max="100" value="0">
</div>
<div class="filter-card rounded-lg p-4" data-filter="invert">
<div class="flex items-center justify-between mb-3">
<span class="text-sm font-medium">Invert</span>
<span class="mono text-xs px-2 py-0.5 rounded" style="background: var(--bg);" id="invert-value">0%</span>
</div>
<input type="range" class="slider-track" id="invert" min="0" max="100" value="0">
</div>
<div class="filter-card rounded-lg p-4" data-filter="hueRotate">
<div class="flex items-center justify-between mb-3">
<span class="text-sm font-medium">Hue Rotate</span>
<span class="mono text-xs px-2 py-0.5 rounded" style="background: var(--bg);" id="hueRotate-value">0°</span>
</div>
<input type="range" class="slider-track" id="hueRotate" min="0" max="360" value="0">
</div>
</div>
<!-- Artistic -->
<div class="space-y-2">
<h3 class="text-xs uppercase tracking-wider mono" style="color: var(--muted);">Artistic</h3>
<div class="filter-card rounded-lg p-4" data-filter="vignette">
<div class="flex items-center justify-between mb-3">
<span class="text-sm font-medium">Vignette</span>
<span class="mono text-xs px-2 py-0.5 rounded" style="background: var(--bg);" id="vignette-value">0</span>
</div>
<input type="range" class="slider-track" id="vignette" min="0" max="100" value="0">
</div>
<div class="filter-card rounded-lg p-4" data-filter="noise">
<div class="flex items-center justify-between mb-3">
<span class="text-sm font-medium">Film Grain</span>
<span class="mono text-xs px-2 py-0.5 rounded" style="background: var(--bg);" id="noise-value">0</span>
</div>
<input type="range" class="slider-track" id="noise" min="0" max="100" value="0">
</div>
<div class="filter-card rounded-lg p-4" data-filter="pixelate">
<div class="flex items-center justify-between mb-3">
<span class="text-sm font-medium">Pixelate</span>
<span class="mono text-xs px-2 py-0.5 rounded" style="background: var(--bg);" id="pixelate-value">1</span>
</div>
<input type="range" class="slider-track" id="pixelate" min="1" max="32" value="1">
</div>
</div>
<!-- Advanced -->
<div class="space-y-2">
<h3 class="text-xs uppercase tracking-wider mono" style="color: var(--muted);">Advanced</h3>
<div class="filter-card rounded-lg p-4" data-filter="posterize">
<div class="flex items-center justify-between mb-3">
<span class="text-sm font-medium">Posterize</span>
<span class="mono text-xs px-2 py-0.5 rounded" style="background: var(--bg);" id="posterize-value">256</span>
</div>
<input type="range" class="slider-track" id="posterize" min="2" max="256" value="256">
</div>
<div class="filter-card rounded-lg p-4" data-filter="threshold">
<div class="flex items-center justify-between mb-3">
<span class="text-sm font-medium">Threshold</span>
<span class="mono text-xs px-2 py-0.5 rounded" style="background: var(--bg);" id="threshold-value">0</span>
</div>
<input type="range" class="slider-track" id="threshold" min="0" max="255" value="0">
</div>
<div class="filter-card rounded-lg p-4" data-filter="emboss">
<div class="flex items-center justify-between mb-3">
<span class="text-sm font-medium">Emboss</span>
<span class="mono text-xs px-2 py-0.5 rounded" style="background: var(--bg);" id="emboss-value">0</span>
</div>
<input type="range" class="slider-track" id="emboss" min="0" max="100" value="0">
</div>
</div>
</div>
</div>
</div>
<input type="file" id="fileInput" accept="image/*" class="hidden">
<script>
// State Management
const state = {
originalImage: null,
filters: {
brightness: 0,
contrast: 0,
saturation: 0,
exposure: 0,
blur: 0,
sharpen: 0,
grayscale: 0,
sepia: 0,
invert: 0,
hueRotate: 0,
vignette: 0,
noise: 0,
pixelate: 1,
posterize: 256,
threshold: 0,
emboss: 0
},
isComparing: false,
isProcessing: false
};
// DOM Elements
const mainCanvas = document.getElementById('mainCanvas');
const originalCanvas = document.getElementById('originalCanvas');
const ctx = mainCanvas.getContext('2d', { willReadFrequently: true });
const origCtx = originalCanvas.getContext('2d', { willReadFrequently: true });
const dropZone = document.getElementById('dropZone');
const fileInput = document.getElementById('fileInput');
const comparisonSlider = document.getElementById('comparisonSlider');
const processingIndicator = document.getElementById('processingIndicator');
const pipelineList = document.getElementById('pipelineList');
const filterCount = document.getElementById('filterCount');
const compareToggle = document.getElementById('compareToggle');
// Initialize canvas dimensions
function initCanvas(width, height) {
mainCanvas.width = width;
mainCanvas.height = height;
originalCanvas.width = width;
originalCanvas.height = height;
}
// Load image
function loadImage(src) {
const img = new Image();
img.crossOrigin = 'anonymous';
img.onload = () => {
state.originalImage = img;
const maxSize = 1200;
let width = img.width;
let height = img.height;
if (width > maxSize || height > maxSize) {
const ratio = Math.min(maxSize / width, maxSize / height);
width = Math.floor(width * ratio);
height = Math.floor(height * ratio);
}
initCanvas(width, height);
ctx.drawImage(img, 0, 0, width, height);
origCtx.drawImage(img, 0, 0, width, height);
dropZone.style.display = 'none';
processImage();
};
img.onerror = () => {
alert('Failed to load image. Please try another.');
};
img.src = src;
}
// Generate sample image using canvas
function generateSampleImage() {
const tempCanvas = document.createElement('canvas');
tempCanvas.width = 800;
tempCanvas.height = 600;
const tempCtx = tempCanvas.getContext('2d');
// Gradient background
const gradient = tempCtx.createLinearGradient(0, 0, 800, 600);
gradient.addColorStop(0, '#1a1a2e');
gradient.addColorStop(0.5, '#16213e');
gradient.addColorStop(1, '#0f3460');
tempCtx.fillStyle = gradient;
tempCtx.fillRect(0, 0, 800, 600);
// Add shapes
for (let i = 0; i < 15; i++) {
const x = Math.random() * 800;
const y = Math.random() * 600;
const radius = Math.max(10, Math.random() * 80);
const hue = Math.random() * 60 + 160;
tempCtx.beginPath();
tempCtx.arc(x, y, radius, 0, Math.PI * 2);
tempCtx.fillStyle = `hsla(${hue}, 70%, 50%, ${Math.random() * 0.5 + 0.1})`;
tempCtx.fill();
}
// Add some lines
tempCtx.strokeStyle = 'rgba(0, 229, 199, 0.3)';
tempCtx.lineWidth = 2;
for (let i = 0; i < 10; i++) {
tempCtx.beginPath();
tempCtx.moveTo(Math.random() * 800, Math.random() * 600);
tempCtx.lineTo(Math.random() * 800, Math.random() * 600);
tempCtx.stroke();
}
// Add text
tempCtx.fillStyle = '#ffffff';
tempCtx.font = 'bold 48px Space Grotesk, sans-serif';
tempCtx.textAlign = 'center';
tempCtx.fillText('Sample Image', 400, 280);
tempCtx.font = '20px Space Grotesk, sans-serif';
tempCtx.fillStyle = 'rgba(255,255,255,0.6)';
tempCtx.fillText('Apply filters to see the effect', 400, 330);
return tempCanvas.toDataURL('image/png');
}
// Process image with all filters
function processImage() {
if (!state.originalImage || state.isProcessing) return;
state.isProcessing = true;
processingIndicator.classList.add('active');
requestAnimationFrame(() => {
const width = mainCanvas.width;
const height = mainCanvas.height;
// Reset to original
ctx.clearRect(0, 0, width, height);
ctx.drawImage(state.originalImage, 0, 0, width, height);
// Get image data
let imageData = ctx.getImageData(0, 0, width, height);
let data = imageData.data;
// Apply filters in order
const activeFilters = getActiveFilters();
// CSS-like filters first
if (state.filters.pixelate > 1) {
imageData = applyPixelate(imageData, state.filters.pixelate);
data = imageData.data;
}
if (state.filters.blur > 0) {
imageData = applyBlur(imageData, Math.floor(state.filters.blur));
data = imageData.data;
}
if (state.filters.sharpen > 0) {
imageData = applySharpen(imageData, state.filters.sharpen / 100);
data = imageData.data;
}
if (state.filters.emboss > 0) {
imageData = applyEmboss(imageData, state.filters.emboss / 100);
data = imageData.data;
}
// Pixel-level operations
for (let i = 0; i < data.length; i += 4) {
let r = data[i];
let g = data[i + 1];
let b = data[i + 2];
// Brightness
if (state.filters.brightness !== 0) {
const adj = state.filters.brightness * 2.55;
r += adj;
g += adj;
b += adj;
}
// Exposure
if (state.filters.exposure !== 0) {
const factor = Math.pow(2, state.filters.exposure / 50);
r *= factor;
g *= factor;
b *= factor;
}
// Contrast
if (state.filters.contrast !== 0) {
const factor = (259 * (state.filters.contrast + 255)) / (255 * (259 - state.filters.contrast));
r = factor * (r - 128) + 128;
g = factor * (g - 128) + 128;
b = factor * (b - 128) + 128;
}
// Saturation
if (state.filters.saturation !== 0) {
const gray = 0.2989 * r + 0.587 * g + 0.114 * b;
const factor = (state.filters.saturation + 100) / 100;
r = gray + factor * (r - gray);
g = gray + factor * (g - gray);
b = gray + factor * (b - gray);
}
// Grayscale
if (state.filters.grayscale > 0) {
const gray = 0.2989 * r + 0.587 * g + 0.114 * b;
const factor = state.filters.grayscale / 100;
r = r * (1 - factor) + gray * factor;
g = g * (1 - factor) + gray * factor;
b = b * (1 - factor) + gray * factor;
}
// Sepia
if (state.filters.sepia > 0) {
const factor = state.filters.sepia / 100;
const sr = Math.min(255, (r * 0.393) + (g * 0.769) + (b * 0.189));
const sg = Math.min(255, (r * 0.349) + (g * 0.686) + (b * 0.168));
const sb = Math.min(255, (r * 0.272) + (g * 0.534) + (b * 0.131));
r = r * (1 - factor) + sr * factor;
g = g * (1 - factor) + sg * factor;
b = b * (1 - factor) + sb * factor;
}
// Hue Rotate
if (state.filters.hueRotate > 0) {
const angle = state.filters.hueRotate * Math.PI / 180;
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const nr = r * (0.213 + cos * 0.787 - sin * 0.213) + g * (0.715 - cos * 0.715 - sin * 0.715) + b * (0.072 - cos * 0.072 + sin * 0.928);
const ng = r * (0.213 - cos * 0.213 + sin * 0.143) + g * (0.715 + cos * 0.285 + sin * 0.140) + b * (0.072 - cos * 0.072 - sin * 0.283);
const nb = r * (0.213 - cos * 0.213 - sin * 0.787) + g * (0.715 - cos * 0.715 + sin * 0.715) + b * (0.072 + cos * 0.928 + sin * 0.072);
r = nr;
g = ng;
b = nb;
}
// Invert
if (state.filters.invert > 0) {
const factor = state.filters.invert / 100;
r = r * (1 - factor) + (255 - r) * factor;
g = g * (1 - factor) + (255 - g) * factor;
b = b * (1 - factor) + (255 - b) * factor;
}
// Posterize
if (state.filters.posterize < 256) {
const levels = state.filters.posterize;
const step = 255 / (levels - 1);
r = Math.round(r / step) * step;
g = Math.round(g / step) * step;
b = Math.round(b / step) * step;
}
// Threshold
if (state.filters.threshold > 0) {
const gray = 0.2989 * r + 0.587 * g + 0.114 * b;
const thresh = gray > state.filters.threshold ? 255 : 0;
const factor = Math.min(1, state.filters.threshold / 128);
r = r * (1 - factor) + thresh * factor;
g = g * (1 - factor) + thresh * factor;
b = b * (1 - factor) + thresh * factor;
}
// Noise
if (state.filters.noise > 0) {
const noiseAmount = state.filters.noise * 0.5;
const noise = (Math.random() - 0.5) * noiseAmount * 2;
r += noise;
g += noise;
b += noise;
}
// Clamp values
data[i] = Math.max(0, Math.min(255, r));
data[i + 1] = Math.max(0, Math.min(255, g));
data[i + 2] = Math.max(0, Math.min(255, b));
}
// Vignette (post-processing)
if (state.filters.vignette > 0) {
applyVignette(imageData, state.filters.vignette / 100);
}
ctx.putImageData(imageData, 0, 0);
state.isProcessing = false;
processingIndicator.classList.remove('active');
updatePipelineUI();
});
}
// Get active filters
function getActiveFilters() {
const active = [];
const defaults = {
brightness: 0, contrast: 0, saturation: 0, exposure: 0,
blur: 0, sharpen: 0, grayscale: 0, sepia: 0, invert: 0,
hueRotate: 0, vignette: 0, noise: 0, pixelate: 1,
posterize: 256, threshold: 0, emboss: 0
};
for (const [key, value] of Object.entries(state.filters)) {
if (value !== defaults[key]) {
active.push(key);
}
}
return active;
}
// Convolution filter helper
function applyConvolution(imageData, kernel, factor = 1) {
const width = imageData.width;
const height = imageData.height;
const src = imageData.data;
const output = new ImageData(width, height);
const dst = output.data;
const size = Math.sqrt(kernel.length);
const half = Math.floor(size / 2);
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
let r = 0, g = 0, b = 0;
for (let ky = 0; ky < size; ky++) {
for (let kx = 0; kx < size; kx++) {
const px = Math.min(width - 1, Math.max(0, x + kx - half));
const py = Math.min(height - 1, Math.max(0, y + ky - half));
const idx = (py * width + px) * 4;
const weight = kernel[ky * size + kx];
r += src[idx] * weight;
g += src[idx + 1] * weight;
b += src[idx + 2] * weight;
}
}
const idx = (y * width + x) * 4;
dst[idx] = Math.max(0, Math.min(255, r * factor + src[idx] * (1 - factor)));
dst[idx + 1] = Math.max(0, Math.min(255, g * factor + src[idx + 1] * (1 - factor)));
dst[idx + 2] = Math.max(0, Math.min(255, b * factor + src[idx + 2] * (1 - factor)));
dst[idx + 3] = src[idx + 3];
}
}
return output;
}
// Sharpen filter
function applySharpen(imageData, amount) {
const kernel = [0, -1, 0, -1, 5, -1, 0, -1, 0];
return applyConvolution(imageData, kernel, amount);
}
// Emboss filter
function applyEmboss(imageData, amount) {
const kernel = [-2, -1, 0, -1, 1, 1, 0, 1, 2];
return applyConvolution(imageData, kernel, amount);
}
// Simple box blur
function applyBlur(imageData, radius) {
const width = imageData.width;
const height = imageData.height;
const src = imageData.data;
const output = new ImageData(width, height);
const dst = output.data;
const safeRadius = Math.max(1, Math.min(radius, Math.floor(Math.min(width, height) / 4)));
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
let r = 0, g = 0, b = 0, count = 0;
for (let dy = -safeRadius; dy <= safeRadius; dy++) {
for (let dx = -safeRadius; dx <= safeRadius; dx++) {
const px = Math.min(width - 1, Math.max(0, x + dx));
const py = Math.min(height - 1, Math.max(0, y + dy));
const idx = (py * width + px) * 4;
r += src[idx];
g += src[idx + 1];
b += src[idx + 2];
count++;
}
}
const idx = (y * width + x) * 4;
dst[idx] = r / count;
dst[idx + 1] = g / count;
dst[idx + 2] = b / count;
dst[idx + 3] = src[idx + 3];
}
}
return output;
}
// Pixelate filter
function applyPixelate(imageData, size) {
const width = imageData.width;
const height = imageData.height;
const safeSize = Math.max(1, Math.min(size, Math.floor(Math.min(width, height) / 2)));
const src = imageData.data;
const output = new ImageData(width, height);
const dst = output.data;
for (let y = 0; y < height; y += safeSize) {
for (let x = 0; x < width; x += safeSize) {
let r = 0, g = 0, b = 0, count = 0;
for (let dy = 0; dy < safeSize && y + dy < height; dy++) {
for (let dx = 0; dx < safeSize && x + dx < width; dx++) {
const idx = ((y + dy) * width + (x + dx)) * 4;
r += src[idx];
g += src[idx + 1];
b += src[idx + 2];
count++;
}
}
r = Math.floor(r / count);
g = Math.floor(g / count);
b = Math.floor(b / count);
for (let dy = 0; dy < safeSize && y + dy < height; dy++) {
for (let dx = 0; dx < safeSize && x + dx < width; dx++) {
const idx = ((y + dy) * width + (x + dx)) * 4;
dst[idx] = r;
dst[idx + 1] = g;
dst[idx + 2] = b;
dst[idx + 3] = src[idx + 3];
}
}
}
}
return output;
}
// Vignette effect
function applyVignette(imageData, amount) {
const width = imageData.width;
const height = imageData.height;
const data = imageData.data;
const cx = width / 2;
const cy = height / 2;
const maxDist = Math.sqrt(cx * cx + cy * cy);
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const idx = (y * width + x) * 4;
const dx = x - cx;
const dy = y - cy;
const dist = Math.sqrt(dx * dx + dy * dy) / maxDist;
const vignette = 1 - (dist * dist * amount);
data[idx] *= vignette;
data[idx + 1] *= vignette;
data[idx + 2] *= vignette;
}
}
}
// Update pipeline UI
function updatePipelineUI() {
const active = getActiveFilters();
filterCount.textContent = `${active.length} filter${active.length !== 1 ? 's' : ''}`;
if (active.length === 0) {
pipelineList.innerHTML = '<span class="text-sm" style="color: var(--muted);">No filters applied</span>';
return;
}
pipelineList.innerHTML = active.map(name => {
const value = state.filters[name];
const displayValue = formatFilterValue(name, value);
return `
<span class="inline-flex items-center gap-1.5 px-2 py-1 rounded-md text-xs mono"
style="background: var(--accent-dim); color: var(--accent);">
${name}
<span style="opacity: 0.7">${displayValue}</span>
</span>
`;
}).join('<span style="color: var(--muted);">→</span>');
}
// Format filter value for display
function formatFilterValue(name, value) {
const defaults = { pixelate: 1, posterize: 256 };
if (defaults[name] !== undefined) {
return value !== defaults[name] ? `(${value})` : '';
}
return value !== 0 ? `(${value})` : '';
}
// Update filter card active state
function updateFilterCardState(name, value) {
const card = document.querySelector(`[data-filter="${name}"]`);
const defaults = { pixelate: 1, posterize: 256 };
const defaultValue = defaults[name] !== undefined ? defaults[name] : 0;
if (card) {
if (value !== defaultValue) {
card.classList.add('active');
} else {
card.classList.remove('active');
}
}
}
// Debounce helper
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
const debouncedProcess = debounce(processImage, 30);
// Setup filter listeners
function setupFilterListeners() {
const filterInputs = document.querySelectorAll('.slider-track');
filterInputs.forEach(input => {
const filterName = input.id;
const valueDisplay = document.getElementById(`${filterName}-value`);
input.addEventListener('input', () => {
let value = parseFloat(input.value);
state.filters[filterName] = value;
// Update value display
if (valueDisplay) {
if (filterName === 'hueRotate') {
valueDisplay.textContent = `${value}°`;
} else if (['grayscale', 'sepia', 'invert'].includes(filterName)) {
valueDisplay.textContent = `${value}%`;
} else if (filterName === 'posterize') {
valueDisplay.textContent = value;
} else if (filterName === 'pixelate') {
valueDisplay.textContent = value;
} else if (filterName === 'threshold') {
valueDisplay.textContent = value;
} else {
valueDisplay.textContent = value > 0 ? `+${value}` : value;
}
}
updateFilterCardState(filterName, value);
debouncedProcess();
});
});
}
// Comparison slider
function setupComparisonSlider() {
let isDragging = false;
const container = document.getElementById('canvasContainer');
comparisonSlider.addEventListener('mousedown', () => isDragging = true);
document.addEventListener('mouseup', () => isDragging = false);
document.addEventListener('mousemove', (e) => {
if (!isDragging) return;
const rect = container.getBoundingClientRect();
const x = Math.max(0, Math.min(rect.width, e.clientX - rect.left));
const percent = (x / rect.width) * 100;
comparisonSlider.style.left = `${percent}%`;
originalCanvas.style.clipPath = `inset(0 ${100 - percent}% 0 0)`;
});
// Touch support
comparisonSlider.addEventListener('touchstart', () => isDragging = true);
document.addEventListener('touchend', () => isDragging = false);
document.addEventListener('touchmove', (e) => {
if (!isDragging) return;
const rect = container.getBoundingClientRect();
const touch = e.touches[0];
const x = Math.max(0, Math.min(rect.width, touch.clientX - rect.left));
const percent = (x / rect.width) * 100;
comparisonSlider.style.left = `${percent}%`;
originalCanvas.style.clipPath = `inset(0 ${100 - percent}% 0 0)`;
});
}
// Event Listeners
document.getElementById('uploadBtn').addEventListener('click', () => fileInput.click());
document.getElementById('loadSampleBtn').addEventListener('click', () => {
loadImage(generateSampleImage());
});
fileInput.addEventListener('change', (e) => {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = (event) => loadImage(event.target.result);
reader.readAsDataURL(file);
}
});
// Drag and drop
dropZone.addEventListener('dragover', (e) => {
e.preventDefault();
dropZone.classList.add('drag-over');
});
dropZone.addEventListener('dragleave', () => {
dropZone.classList.remove('drag-over');
});
dropZone.addEventListener('drop', (e) => {
e.preventDefault();
dropZone.classList.remove('drag-over');
const file = e.dataTransfer.files[0];
if (file && file.type.startsWith('image/')) {
const reader = new FileReader();
reader.onload = (event) => loadImage(event.target.result);
reader.readAsDataURL(file);
}
});
// Compare toggle
compareToggle.addEventListener('change', function() {
state.isComparing = this.checked;
comparisonSlider.style.display = this.checked ? 'block' : 'none';
originalCanvas.style.clipPath = this.checked ? 'inset(0 50% 0 0)' : 'inset(0 100% 0 0)';
comparisonSlider.style.left = '50%';
// Update toggle visual
const thumb = this.nextElementSibling.querySelector('div');
if (this.checked) {
this.nextElementSibling.style.background = 'var(--accent)';
thumb.style.transform = 'translateX(16px)';
thumb.style.background = 'var(--bg)';
} else {
this.nextElementSibling.style.background = 'var(--border)';
thumb.style.transform = 'translateX(0)';
thumb.style.background = 'var(--muted)';
}
});
// Reset all filters
document.getElementById('resetAllBtn').addEventListener('click', () => {
const defaults = {
brightness: 0, contrast: 0, saturation: 0, exposure: 0,
blur: 0, sharpen: 0, grayscale: 0, sepia: 0, invert: 0,
hueRotate: 0, vignette: 0, noise: 0, pixelate: 1,
posterize: 256, threshold: 0, emboss: 0
};
for (const [key, value] of Object.entries(defaults)) {
state.filters[key] = value;
const input = document.getElementById(key);
if (input) input.value = value;
const valueDisplay = document.getElementById(`${key}-value`);
if (valueDisplay) {
if (key === 'hueRotate') {
valueDisplay.textContent = '0°';
} else if (['grayscale', 'sepia', 'invert'].includes(key)) {
valueDisplay.textContent = '0%';
} else if (key === 'posterize') {
valueDisplay.textContent = '256';
} else if (key === 'pixelate') {
valueDisplay.textContent = '1';
} else if (key === 'threshold') {
valueDisplay.textContent = '0';
} else {
valueDisplay.textContent = '0';
}
}
updateFilterCardState(key, value);
}
processImage();
});
// Download
document.getElementById('downloadBtn').addEventListener('click', () => {
if (!state.originalImage) {
alert('Please load an image first');
return;
}
const link = document.createElement('a');
link.download = 'processed-image.png';
link.href = mainCanvas.toDataURL('image/png');
link.click();
});
// Initialize
setupFilterListeners();
setupComparisonSlider();
</script>
</body>
</html>
Features
16 Professional Filters:
- Basic Adjustments: Brightness, Contrast, Saturation, Exposure
- Blur & Sharpen: Gaussian Blur, Sharpen (convolution-based)
- Color Effects: Grayscale, Sepia, Invert, Hue Rotate
- Artistic: Vignette, Film Grain, Pixelate
- Advanced: Posterize, Threshold, Emboss
Interactive Features:
- Real-time Processing - All filters apply instantly with debounced updates
- Before/After Comparison - Draggable slider to compare with original
- Pipeline Visualization - See active filters as a flow diagram
- Drag & Drop Upload - Or load a sample image to start
- Filter State Indicators - Active filters highlight with accent color
- Export Functionality - Download processed image as PNG
Design Highlights:
- Dark technical aesthetic with cyan accent
- Grid background with subtle glow effects
- Space Grotesk + JetBrains Mono typography
- Smooth animations with reduced-motion support
- Fully responsive layout
- Professional filter cards with live value display