- Most cloud photo enhancers require uploading private photos to remote GPU clusters, creating permanent data retention and surveillance liabilities.
- Modern web browsers execute neural super-resolution models directly in client RAM using ONNX Runtime Web and WebGPU compute shaders.
- Fixed-shape neural architectures like PurePhoto require strict 256x256 NCHW tensor matrices. Splitting inputs into overlapping tiles with clamp-to-edge border padding prevents tensor shape exceptions while eliminating dark boundary halos.
- Overlapping adjacent tiles by 16 pixels enables linear feathering that erases visible grid boundaries.
- Automatic runtime negotiation dispatches WebGPU on desktop hardware and safely falls back to single-threaded WebAssembly on mobile Safari, preventing iOS WebKit JSEP out-of-memory browser tab kills.
The Privacy Crisis of Cloud-Based Photo Enhancement
Online photo enhancers typically operate as thin client facades over cloud compute clusters. When an image is uploaded, it is written to server storage and processed on remote Python runtimes.
This server-side workflow introduces severe privacy risks: persistent scratch disk storage, third-party network interception, and unnecessary cellular data consumption.
Modern client devices feature graphics processors capable of computing billions of operations per second. By leveraging WebGPU and ONNX Runtime Web, web applications execute super-resolution networks entirely in local device memory, guaranteeing that sensitive visual data never leaves your device. Test this architecture directly in our companion Free AI Image Upscaler tool.
WebGPU Acceleration with Resilient Safari WASM Fallback
Executing deep-learning models in browser RAM requires a high-throughput bridge to graphics hardware. WebGPU exposes modern compute shader pipelines directly to web applications, dispatching matrix multiplication across hundreds of parallel GPU cores with minimal driver overhead. On desktop operating systems running Chrome, Edge, or Firefox, WebGPU processes a 256x256 image tile in under 40 milliseconds.
async function initializeInferenceSession(modelBinary) {
const isSafari = typeof navigator !== 'undefined' && (
/iPad|iPhone|iPod/.test(navigator.userAgent) ||
(/^((?!chrome|android).)*safari/i.test(navigator.userAgent))
);
if (!isSafari && typeof navigator !== 'undefined' && navigator.gpu) {
try {
return await ort.InferenceSession.create(modelBinary, { executionProviders: ['webgpu'] });
} catch (err) {
console.warn('WebGPU failed, switching to WASM:', err);
}
}
ort.env.wasm.numThreads = 1; // Resilient mobile Safari fallback
return await ort.InferenceSession.create(modelBinary, { executionProviders: ['wasm'] });
}However, hardware heterogeneity presents a critical engineering challenge. On Apple iOS devices and Safari, WebGPU implementation details or system permission gates frequently trigger WebKit JavaScript Execution Proxy (JSEP) memory spikes, causing browser tab crashes.
To ensure universal reliability, our engine performs proactive runtime negotiation. If the user agent indicates Safari or iOS hardware, or if WebGPU initialization fails, the worker falls back to single-threaded WebAssembly (ort.env.wasm.numThreads = 1). While WASM processing takes slightly longer per tile, it consumes a strictly bounded memory footprint, ensuring mobile devices upscale photos without tab crashes.
Fixed-Shape 256x256 Tiling and Clamp-to-Edge Border Padding
The super-resolution model used in our engine is PurePhoto 4xNomosUni, a compact 1.65 MB neural network trained specifically for realistic texture recovery and edge sharpening. It features a static input shape: exactly [1, 3, 256, 256] in NCHW format with normalized float32 pixel values in [0.0, 1.0]. Feeding arbitrary dynamic crops causes ONNX runtime shape mismatch exceptions. Input images must be segmented into uniform 256x256 tiles.
function extractTileTensor(pixels, width, height, startX, startY) {
const TILE = 256; const PLANE = 65536;
const nchw = new Float32Array(3 * PLANE);
for (let ty = 0; ty < TILE; ty++) {
const srcY = Math.min(startY + ty, height - 1);
for (let tx = 0; tx < TILE; tx++) {
const srcX = Math.min(startX + tx, width - 1);
const srcIdx = (srcY * width + srcX) * 4;
const idx = ty * TILE + tx;
nchw[idx] = pixels[srcIdx] / 255.0;
nchw[PLANE + idx] = pixels[srcIdx + 1] / 255.0;
nchw[2 * PLANE + idx] = pixels[srcIdx + 2] / 255.0;
}
}
return new ort.Tensor('float32', nchw, [1, 3, TILE, TILE]);
}When image dimensions are not exact multiples of 256, perimeter tiles extend beyond canvas bounds. Zero-padding missing pixels with black values creates dark halos because convolutional networks interpret sharp transitions to black as high-frequency image edges.
Our architecture applies replicate border padding (clamp-to-edge). When tile coordinates exceed canvas bounds, the extraction loop clamps to the nearest valid edge pixel (Math.min(x, width - 1)). This satisfies static tensor requirements while completely preventing edge artifacts.
Eliminating Seams: Overlap Feathering and 2x Canvas Downsampling
Because super-resolution neural networks process each 256x256 tile independently, subtle variations in local contrast and color grading can emerge between adjacent outputs, creating visible grid lines.
To completely eliminate grid seams, adjacent input tiles overlap by 16 pixels (mapping to 64 pixels in 4x reconstruction space). Across this 64-pixel corridor, our engine applies linear feathering interpolation:
function blendTile(dest, outData, x0, y0, destW, destH) {
const OUT_TILE = 1024; const OVERLAP = 64; const PLANE = 1048576;
for (let ty = 0; ty < OUT_TILE; ty++) {
const dstY = y0 + ty; if (dstY >= destH) break;
const wy = (y0 > 0 && ty < OVERLAP) ? (ty / OVERLAP) : 1.0;
for (let tx = 0; tx < OUT_TILE; tx++) {
const dstX = x0 + tx; if (dstX >= destW) break;
const wx = (x0 > 0 && tx < OVERLAP) ? (tx / OVERLAP) : 1.0;
const w = wx * wy;
const idx = ty * OUT_TILE + tx;
const dstIdx = (dstY * destW + dstX) * 4;
dest[dstIdx] = Math.round(dest[dstIdx] * (1 - w) + outData[idx] * 255 * w);
dest[dstIdx + 1] = Math.round(dest[dstIdx + 1] * (1 - w) + outData[PLANE + idx] * 255 * w);
dest[dstIdx + 2] = Math.round(dest[dstIdx + 2] * (1 - w) + outData[2 * PLANE + idx] * 255 * w);
dest[dstIdx + 3] = 255;
}
}
}While the neural network natively produces 4x magnification, users frequently require a 2x enlargement. Rather than maintaining a separate 2x model, the engine generates the full 4x reconstruction and downsamples it by 50% using high-precision bicubic canvas interpolation (ctx.imageSmoothingQuality = 'high').
Memory Leak Defenses: Explicit Tensor Disposal and Cache Storage
Running deep-learning inference inside web pages introduces memory leak risks. WebGPU allocates memory directly on graphics cards, while WebAssembly manages linear heap memory. Relying on automatic garbage collection causes VRAM and system memory to balloon rapidly.
tensor.dispose() immediately after extracting tensor data. In an un-disposed 16-tile upscaling pass, lingering tensors consume over 480 MB of graphics memory. With explicit disposal, memory consumption remains flat at roughly 105 MB throughout the run.const results = await session.run(feeds);
inputTensor.dispose(); // Release GPU buffer immediately
const outputTensor = results[session.outputNames[0]];
blendTile(destPixels, outputTensor.data, x0 * 4, y0 * 4, outW, outH);
outputTensor.dispose(); // Release output buffer immediately- Zero Page-Load Overhead: Neither ONNX Runtime nor model weights load on page mount, preserving instant First Contentful Paint. Dynamic loading occurs after file selection.
- Cache Storage Persistence: The model binary is cached via Cache Storage (
caches.open('poofshare-ai-models-v1')). Subsequent sessions load instantly with zero network requests.
Client-Side Upscaling Performance Matrix
| Metric Dimension | Desktop WebGPU Mode | Mobile Safari WASM Mode | Cloud Processing Facade |
|---|---|---|---|
| Inference Latency per Tile | 25 ms to 45 ms | 280 ms to 420 ms | 1,200 ms to 3,500 ms (network) |
| Network Egress per Photo | 0 Bytes (100% Local) | 0 Bytes (100% Local) | Full uncompressed file upload |
| Data Retention Risk | Zero (Volatile RAM only) | Zero (Volatile RAM only) | Third-party cloud disk storage |
| Model Weight Caching | Cache Storage (1.65 MB) | Cache Storage (1.65 MB) | N/A (Server hosted) |
| VRAM Memory Stability | Flat 105 MB via dispose() | Flat 65 MB linear heap | Uncontrolled server scaling |
| Offline Execution | Fully Supported | Fully Supported | Fails completely |
Summary and Ephemeral Sharing Integration
Client-side super-resolution unifies high-performance neural inference with local data privacy. By dividing images into uniform 256x256 tiles with replicate border padding and 16-pixel seam feathering, web applications enhance photos locally with zero server dependency.
Once upscaled, photos can be downloaded directly or staged into our ephemeral sharing workflow. Clicking "Share via Expiring Link" securely hands off the image to PoofShare's automated expiring upload service, generating an auto-destructing URL protected by strict zero-log privacy policies.
Related Engineering Guides
- How to Compress Images to an Exact Target KB in Browser Memory: Binary search quantization algorithms and canvas downscaling techniques.
- Building a Zero-Upload PDF Assembler and Page Extractor: Constructing PDF object trees and high-DPI canvas extractions in local RAM.
- Privacy Policy and About PoofShare: Learn how PoofShare eliminates persistent tracking and automated data retention.
How does client-side AI image upscaling work without uploading my files?
The neural network runs locally in your web browser. The browser downloads the compact 1.65 MB ONNX model once, caches it in Cache Storage, and executes inference directly on your graphics card (via WebGPU) or processor (via WebAssembly). No image data is ever transmitted across the internet.
What is the difference between the 2x and 4x scaling modes?
The neural network natively generates a 4x super-resolution reconstruction for every tile. When you select 4x, the full 4x pixel matrix is rendered directly. When you select 2x, the engine takes the 4x intermediate canvas and downsamples it by 50% using bicubic interpolation, providing cleaner lines and sharper textures.
Why is there an input resolution limit of 1280 pixels?
A 1280x1280 input image produces a massive 5120x5120 canvas at 4x scale, containing over 26 million pixels and requiring more than 100 megabytes of raw uncompressed RGBA memory. Capping input dimensions prevents mobile browsers from terminating web tabs due to canvas memory limits.
Who created the underlying AI model and what are its licensing terms?
The tool uses the PurePhoto 4xNomosUni super-resolution model developed by Philip Hofmann and released under the Creative Commons Attribution 4.0 International license (CC BY 4.0).