A phone photo is not one object. It is an image plus a set of records about the image: capture time, device model, serial number, editing software, and — when location was on — coordinates accurate to a few metres. Those records sit in the same file, in a structure the format defines.

That matters because "remove metadata" describes two very different operations. One decodes the pixels and encodes them again. The other walks the container and cuts records out. Canvas makes the first one easy — three lines — and it also throws away the original compression and changes pixel values slightly. The second is what this post is about: reading the bytes, finding the records, removing them, and leaving the compressed image data alone.

Everything below uses File, ArrayBuffer and DataView, none of which needs a server. I ran the parsers in Node 22 against a JPEG, an MP4 and a HEIC file I generated locally; the browser path is the same code, because DataView does not care where the buffer came from. I did not benchmark anything, and the numbers below are structural, not performance claims.

A JPEG is a list of segments

A JPEG opens with FF D8 (start of image), then a chain of segments. Each segment starts with FF and a marker byte, and most carry a two-byte big-endian length that counts the length field itself. The chain ends at FF DA (start of scan), where the compressed image data begins and runs to FF D9 at the end of the file.

Marker Name Normally carries
FF E0 APP0 JFIF header: density, small thumbnail
FF E1 APP1 EXIF (an embedded TIFF) or XMP (an XML packet)
FF E2 APP2 ICC colour profile, sometimes MPF
FF EB APP11 C2PA manifest, as JUMBF boxes
FF ED APP13 Photoshop image resources, including IPTC
FF EE APP14 Adobe colour transform flag

GPS is not a top-level field. It lives inside the EXIF block, which is a small TIFF file: a header, a directory of 12-byte tag entries, and offsets to further directories. In the first directory, tag 0x8825 is a pointer to the GPS directory, where latitude and longitude are stored as three rational numbers each. Because everything is addressed by offset, editing a field in place is delicate: change one value's length and every offset after it is wrong.

Two traps follow from that layout. EXIF and XMP are separate APP1 segments with separate vocabularies, and XMP keeps its own copy of exif:GPSLatitude and exif:GPSLongitude, so a cleaner that removes "EXIF" and leaves XMP has removed nothing useful. IPTC is in APP13, inside a Photoshop resource block, so it survives any pass that only looks at APP1. And one JPEG can hold several APP1 segments, because EXIF plus standard XMP plus extended XMP do not fit in one.

Here is the walk. It reads the header only, so the cost does not grow with the size of the photo:

const JPEG_NAMES = { 0xe0: "APP0", 0xe1: "APP1", 0xe2: "APP2", 0xeb: "APP11", 0xed: "APP13", 0xee: "APP14", 0xda: "SOS", 0xd9: "EOI", }; function jpegSegments(buffer) { const view = new DataView(buffer); if (view.getUint16(0) !== 0xffd8) throw new Error("Not a JPEG"); const found = []; let offset = 2; // just past SOI while (offset + 4 <= view.byteLength) { if (view.getUint8(offset) !== 0xff) break; let marker = view.getUint8(offset + 1); while (marker === 0xff) { // fill bytes before a marker offset += 1; marker = view.getUint8(offset + 1); } if (marker === 0x01 || (marker >= 0xd0 && marker <= 0xd8)) { offset += 2; // no length field on these continue; } if (marker === 0xd9) break; const length = view.getUint16(offset + 2); const end = offset + 2 + length; // length includes its own 2 bytes found.push({ marker, name: JPEG_NAMES[marker] ?? "0x" + marker.toString(16), offset, end }); if (marker === 0xda) break; // pixels start here offset = end; } return found; } 

On the JPEG I tested — a HEIC exported by macOS — the walk returns a 5,933-byte APP1 (EXIF), an APP10 whose payload starts with AROT, the quantisation and Huffman tables, then SOS. There is no APP0 at all. That APP10 is Apple's HDR gain-map curve, which ExifTool reports as HDRGainInfo; drop every segment you do not recognise and an HDR photo comes out flatter. Which is the argument for deciding by name rather than by "unknown, therefore disposable".

Cutting a segment out changes the file, not the pixels

function withoutSegments(buffer, segments) { const parts = []; let cursor = 0; for (const s of segments) { // sorted by offset parts.push(new Uint8Array(buffer, cursor, s.offset - cursor)); cursor = s.end; } parts.push(new Uint8Array(buffer, cursor)); return new Blob(parts, { type: "image/jpeg" }); } 

No decoder runs. The bytes from FF DA to the end of the file are passed through untouched, which is the property worth checking after any cleanup: extract the scan data before and after, and compare.

What does change is the file. A hash covers every byte, so the hash of the cleaned photo is different, even though not one pixel changed. That breaks assumptions downstream: content-addressed storage treats the result as a new object, a stored ETag no longer matches, and a pipeline that de-duplicates by hash sees two files. The size shrinks by exactly the removed segments — two bytes of marker plus the declared length for each.

The alternative is zeroing the payload in place. The file keeps its size and every offset stays valid, which matters inside containers whose index you would rather not rewrite. But the hash still changes, and the segment is still there with a body full of zeros; some parsers report an empty metadata block rather than no metadata. That is a different output from a real removal, and it is worth knowing which one a tool produces.

One segment deserves a second thought before you drop it: EXIF tag 0x0112, orientation. Viewers rotate the image according to that tag, so a portrait photo stripped of it displays sideways unless the rotation is baked into the pixels. Keeping that one value is usually the smaller problem.

HEIC and MP4: the same idea, with absolute offsets

HEIC and MP4 are both ISO base media file format: a tree of boxes, each with a 32-bit size, a four-character type, then a body. Two size values are special. 1 means the real size is a 64-bit value in the next eight bytes; 0 means the box runs to the end of the file. A uuid box carries 16 more bytes of type. And meta is a full box, so its children start four bytes later than you would expect — version and flags first. That last detail is where hand-written parsers usually break.

The records sit in predictable places. moov/udta/©xyz is the classic QuickTime location box, holding a string like +31.2304+121.4737/. 3GPP encoders put the same string under moov/udta/loci. Apple's newer files use moov/udta/meta with a keys table and an ilst list. HEIC puts a top-level meta box whose iloc table points at the image data.

const CONTAINERS = new Set(["moov", "trak", "mdia", "minf", "stbl", "udta", "meta"]); function boxes(buffer, start = 0, end = buffer.byteLength, depth = 0) { const view = new DataView(buffer); const found = []; let offset = start; while (offset + 8 <= end) { let size = view.getUint32(offset); const type = String.fromCharCode(...new Uint8Array(buffer, offset + 4, 4)); let header = 8; if (size === 1) { size = Number(view.getBigUint64(offset + 8)); header = 16; } else if (size === 0) { size = end - offset; // last box runs to end of file } if (size < header) break; // corrupt or truncated found.push({ type, offset, size, depth }); if (CONTAINERS.has(type) && depth < 8) { const body = offset + header + (type === "meta" ? 4 : 0); // full box found.push(...boxes(buffer, body, offset + size, depth + 1)); } offset += size; } return found; } 

If your files come from a 3GPP encoder, add loci and place to CONTAINERS to reach the string inside; print the tree before you descend into anything, because not every muxer fills those boxes the way the spec describes.

The reason you cannot simply delete a box is that those offsets are absolute. Removing bytes from moov moves every media sample in mdat, so stco and co64 (chunk offsets), iloc (HEIC item locations), and sometimes saio and sidx, all have to be rewritten to match. The parsing is easy; the bookkeeping is the work. That is the real difference between stripping a JPEG and stripping a video, and it is why re-encoding the video is not the same job.

For HEIC the constraint is tighter. meta is required, and iinf, iloc and pitm have to stay consistent or the file will not open. You remove the location item and fix the tables; you do not remove meta.

C2PA is a different kind of record

A Content Credentials manifest is not another EXIF tag. It is a JUMBF container — APP11 in JPEG, caBX in PNG, a chunk named C2PA in WebP, a uuid box in AVIF and HEIC — holding a claim, a set of assertions, and a COSE signature. The signature covers the claim, and one assertion, the hard binding, is a hash over the asset's bytes with the manifest's own byte range excluded.

The practical consequence: the manifest can be removed without recomputing anything, because its signature only ever attested to a file that included it. It cannot be edited without the signing key, so "changing" one means deleting it or adding a new one. Removing it also changes what a verifier can say. The verifier reports that no manifest was found, which is not the same as reporting that the file is unedited or not AI-generated; only the first claim is checkable.

One more detail: a JPEG manifest with certificates does not fit in the 65,533-byte payload limit, so it is split across several consecutive APP11 segments. Drop one and you have a partial store, which is worse than none.

Three things that bite

The first is the hash, covered above, and it bites hardest in pipelines rather than in browsers. If you de-duplicate by hash, the cleaned file and the original are two objects; if you cache by URL, the cleaned file is a new variant. Decide which behaviour you want before shipping.

The second is that a photo can contain a second image. EXIF directory IFD1 commonly holds a JPEG thumbnail, a complete little file inside APP1. Redact a face by painting over the main image in a tool that preserves metadata, and the thumbnail still shows the original scene. The same is true of the edit history XMP keeps. Segment-level removal takes the thumbnail with the EXIF block; tag-level editing needs a checklist, and most checklists miss IFD1.

The third is that PNG and WebP do not use segments. PNG is chunks: a four-byte length, a four-byte type, the data, and a CRC-32 over the type and data. Metadata is eXIf, tEXt, iTXt, zTXt or caBX, and dropping a chunk needs no recalculation for the chunks that remain, because each carries its own CRC. WebP is a RIFF container, which adds two requirements: the file size field at offset 4 must be updated, and the VP8X flags byte has one bit for EXIF and one for XMP that must be cleared, or a reader will look for chunks that are no longer there. That flag is easy to miss because the image still renders correctly without it.

Checking the output

The test after any of this is cheap: parse the cleaned file again and confirm the walk still reaches the scan header — or, for a box tree, the mdat — then compare the scan data, or the mdat payload, byte for byte with the original. If those bytes match and the segment or box you targeted is gone, you removed metadata without touching the image. If the file no longer parses, you removed something the container needed.

If you would rather not maintain a parser per format, erasemetadata.com does this work in a worker in the tab: it lists each field with its group, value and risk, then rewrites the container instead of re-encoding, and keeps the colour profile and orientation flag. It covers photos, video, PDFs, Office files and audio, and the file never leaves the machine.