When you export an image from a generator, an editor or a phone, the file carries more than pixels. PNG text chunks, EXIF blocks and newer content-credential (C2PA) manifests can record the software, the date and sometimes the prompt. This post shows how to look inside a PNG in the browser with plain JavaScript, so you know what you are about to publish.
PNG is just a list of chunks
A PNG file is an 8-byte signature followed by chunks. Each chunk is:
| Bytes | Meaning |
|---|---|
| 4 | length of the data (big-endian) |
| 4 | type, e.g. IHDR, tEXt, iTXt, eXIf, caBX, IDAT
|
| n | data |
| 4 | CRC |
Text metadata lives in tEXt, zTXt and iTXt chunks. EXIF can live in eXIf. C2PA manifests in PNG use a caBX chunk.
Listing the chunks
async function listPngChunks(file) {
const buf = new DataView(await file.arrayBuffer());
const sig = [137, 80, 78, 71, 13, 10, 26, 10];
if (!sig.every((b, i) => buf.getUint8(i) === b)) throw new Error("not a PNG");
const chunks = [];
let pos = 8;
while (pos < buf.byteLength) {
const len = buf.getUint32(pos);
const type = String.fromCharCode(
buf.getUint8(pos + 4), buf.getUint8(pos + 5),
buf.getUint8(pos + 6), buf.getUint8(pos + 7)
);
chunks.push({ type, len, offset: pos + 8 });
pos += 12 + len;
if (type === "IEND") break;
}
return chunks;
}
Reading text chunks
function readTextChunk(view, { offset, len }) {
const bytes = new Uint8Array(view.buffer, offset, len);
const zero = bytes.indexOf(0);
const key = new TextDecoder("latin1").decode(bytes.slice(0, zero));
const value = new TextDecoder("utf-8").decode(bytes.slice(zero + 1));
return { key, value };
}
This works for tEXt. iTXt has a few extra header fields (compression flag, language tag) before the text, and zTXt is deflate-compressed; you can decompress it with DecompressionStream("deflate") in modern browsers.
Wiring it to a file input
document.querySelector("input[type=file]").addEventListener("change", async (e) => {
const file = e.target.files[0];
const chunks = await listPngChunks(file);
const view = new DataView(await file.arrayBuffer());
for (const c of chunks) {
if (c.type === "tEXt") console.log(readTextChunk(view, c));
else console.log(c.type, c.len, "bytes");
}
});
Everything runs locally; the file never leaves the browser.
Removing metadata
The simplest way to drop all metadata is to redraw the image on a canvas and export it:
const bmp = await createImageBitmap(file);
const canvas = new OffscreenCanvas(bmp.width, bmp.height);
canvas.getContext("2d").drawImage(bmp, 0, 0);
const clean = await canvas.convertToBlob({ type: "image/png" });
The new file contains only pixels. Two things to keep in mind:
- This removes text, EXIF and C2PA data, but not invisible pixel-level watermarks such as SynthID, which are designed to survive re-encoding.
- Removing provenance data does not change the terms under which you may use an image. If a platform asks you to label AI content, label it.
Where this fits
Metadata is one of three layers on AI images, alongside invisible watermarks and small visible corner marks. The same canvas approach is the basis of browser tools that edit pixels without uploading anything; for example, a Gemini watermark remover tool uses canvas inpainting to clean the visible corner mark on your own images. Knowing which layer you are dealing with makes it much easier to reason about what an edit actually changes.
Top comments (0)