Every smartphone photo carries invisible binary headers alongside its pixels: exact GPS latitude and longitude, altitude, camera serial number, lens profile, capture timestamp, and — on modern AI-generated PNGs — the entire text prompt and generation workflow embedded inside tEXt / iTXt chunks.

Most web tutorials suggest "stripping EXIF" by drawing the image onto an HTML <canvas> and exporting canvas.toBlob('image/jpeg', 0.9). That works, but it damages the photo:

  1. It decompresses and re-encodes every single JPEG block (visible generation loss and file bloat).
  2. It silently discards ICC Display-P3 color profiles, making wide-gamut phone photos look washed out.
  3. It cannot perform surgical GPS-only removal when a photographer wants to keep shutter speed, ISO, and lens data intact.

You can solve all three problems cleanly by walking the raw binary segments of JPEG and PNG files inside a Uint8Array — 0% pixel re-encoding, zero external libraries, 100% browser-local.

Here is the core binary stripping architecture behind our free client-side EXIF & GPS Metadata Remover on EasyDailyTools.

1. Lossless JPEG Segment Filtering (Preserving Pixels & ICC Profiles)

A JPEG stream begins with 0xFF 0xD8 (SOI) and contains a sequence of length-prefixed marker segments before 0xFF 0xDA (SOS — Start of Scan). Once you hit 0xFF 0xDA, everything through the end of the file is the Huffman-coded image scan. Never decode it — copy it verbatim.

Before SOS, selectively filter only the metadata segments while keeping quantization tables (DQT), Huffman tables (DHT), frame headers (SOF), and optionally APP2 ICC_PROFILE:

function stripJpegMetadataLossless(bytes, { preserveIcc = true } = {}) { if (bytes.length < 4 || bytes[0] !== 0xff || bytes[1] !== 0xd8) { throw new Error('Not a valid JPEG file'); } const kept = [bytes.subarray(0, 2)]; // SOI let offset = 2; while (offset < bytes.length) { if (bytes[offset] !== 0xff) { kept.push(bytes.subarray(offset)); break; } const markerStart = offset; while (offset < bytes.length && bytes[offset] === 0xff) offset++; const marker = bytes[offset++]; // SOS (0xDA): copy compressed pixel scan untouched to EOF! if (marker === 0xda) { kept.push(bytes.subarray(markerStart)); break; } if (marker === 0xd9 || marker === 0x01 || (marker >= 0xd0 && marker <= 0xd7)) { kept.push(bytes.subarray(markerStart, offset)); if (marker === 0xd9) break; continue; } const segLen = (bytes[offset] << 8) | bytes[offset + 1]; const segEnd = offset + segLen; const dataStart = offset + 2; let drop = false; if (marker === 0xe1 || marker === 0xeb || marker === 0xed || marker === 0xfe) { // APP1 (EXIF / XMP), APP11 (C2PA), APP13 (IPTC), COM (comments) drop = true; } else if (marker === 0xe2) { const sig = String.fromCharCode(...bytes.subarray(dataStart, dataStart + 11)); drop = (sig === 'ICC_PROFILE') ? !preserveIcc : true; } else if (marker >= 0xe3 && marker <= 0xef && marker !== 0xee) { drop = true; } if (!drop) kept.push(bytes.subarray(markerStart, segEnd)); offset = segEnd; } const total = kept.reduce((acc, c) => acc + c.length, 0); const out = new Uint8Array(total); let pos = 0; for (const chunk of kept) { out.set(chunk, pos); pos += chunk.length; } return out; } 

Bonus: Surgical GPS-Only Scrubbing Inside TIFF IFD0

What if a photographer wants to keep camera make, lens, aperture, and ISO — and wipe only the GPS coordinates? Inside the APP1 Exif\0\0 TIFF header, locate tag 0x8825 (GPSInfoIFDPointer), zero-fill both the pointed GPS IFD entries and any rational coordinate arrays (latitude/longitude/altitude), then shift the remaining 12-byte IFD0 entries upward by 12 bytes and decrement the entry count by 1. Zero pixels touched, zero camera metadata lost, zero GPS bytes left behind.

2. Stripping AI Prompts, eXIf, and tEXt Chunks From PNGs

PNG files follow an even cleaner chunk structure after the 8-byte signature (89 50 4E 47 0D 0A 1A 0A). Each chunk is:

[4-byte big-endian length][4-byte ASCII type][length bytes payload][4-byte CRC-32]

Because every chunk carries its own independent CRC-32 checksum, dropping a metadata chunk does not invalidate any other chunk in the file:

function stripPngMetadataLossless(bytes, { preserveIcc = true } = {}) { const kept = [bytes.subarray(0, 8)]; // PNG signature let offset = 8; while (offset + 12 <= bytes.length) { const len = ((bytes[offset] << 24) | (bytes[offset + 1] << 16) | (bytes[offset + 2] << 8) | bytes[offset + 3]) >>> 0; const type = String.fromCharCode( bytes[offset + 4], bytes[offset + 5], bytes[offset + 6], bytes[offset + 7] ); const nextOff = offset + 12 + len; if (nextOff > bytes.length) break; const drop = type === 'eXIf' || type === 'tIME' || type === 'caBX' || // C2PA provenance chunk type === 'tEXt' || // AI prompts, software tags, comments type === 'iTXt' || // UTF-8 XMP & workflow JSON type === 'zTXt' || // Compressed text chunks (type === 'iCCP' && !preserveIcc); if (!drop) kept.push(bytes.subarray(offset, nextOff)); offset = nextOff; } const out = new Uint8Array(kept.reduce((n, c) => n + c.length, 0)); let pos = 0; for (const c of kept) { out.set(c, pos); pos += c.length; } return out; } 

3. Don't Forget Visual Privacy Too

Metadata stripping removes hidden GPS and device serials, while visual redaction removes license plates, faces, and street signs inside the pixels themselves. If you want a complete breakdown of which messaging and social platforms strip EXIF versus which leak raw location headers, see our EXIF & GPS Privacy Guide.

We paired both privacy engines side-by-side in our Image Tools Suite:

Open-Source Code & Offline Desktop Pack

Have you ever caught an unexpected metadata chunk leaking inside PNG or WebP uploads in production? Share your war story below!