How Instagram Detects AI Images: C2PA, IPTC and XMP Explained (With Code to Inspect Them)
If you've ever seen Instagram put an "AI info" label on a photo you know is real, the cause is almost never the pixels. It's metadata. I've spent the last few months building AI Flag Remover, a browser-based tool that st
If you've ever seen Instagram put an "AI info" label on a photo you know is real, the cause is almost never the pixels. It's metadata. I've spent the last few months building AI Flag Remover, a browser-based tool that strips this metadata, so here's what I learned about where it lives and how to inspect it yourself.
The three places AI signals hide
| Signal | Where it lives | Who writes it | Who reads it |
|---|---|---|---|
| C2PA manifest | JUMBF boxes (JPEG APP11, PNG caBX chunk, WebP C2PA chunk) |
Adobe, OpenAI, Google, Microsoft | TikTok, LinkedIn, Meta, Pinterest |
| IPTC Digital Source Type | XMP packet, Iptc4xmpExt:DigitalSourceType
|
Meta AI, many generators | Meta (Instagram, Facebook, Threads) |
| Generator text | PNG tEXt/iTXt chunks (parameters, prompt, workflow) |
Stable Diffusion WebUI, ComfyUI, Forge | Anyone who opens the file |
The IPTC value to look for is a URI ending in trainedAlgorithmicMedia (fully generated) or compositeWithTrainedAlgorithmicMedia (real photo edited with AI). That second one is the usual culprit when a real photo gets labelled after a Generative Fill edit.
Inspecting a file with exiftool
The quickest check, if you have ExifTool installed:
# Show the IPTC digital source type and any C2PA/JUMBF data
exiftool -G1 -a -s -DigitalSourceType -JUMBF:all -XMP-iptcExt:all photo.jpg
# For Stable Diffusion PNGs, show the embedded prompt
exiftool -PNG:Parameters -PNG:Prompt -PNG:Workflow image.png
Detecting C2PA in Python (no dependencies)
C2PA in JPEGs sits in APP11 segments containing a JUMBF box labelled c2pa. This scans the segment markers:
import sys
def find_c2pa_jpeg(path):
data = open(path, "rb").read()
i = 2 # skip SOI
found = []
while i < len(data) - 4 and data[i] == 0xFF:
marker = data[i + 1]
length = int.from_bytes(data[i + 2:i + 4], "big")
segment = data[i + 4:i + 2 + length]
if marker == 0xEB and b"c2pa" in segment: # APP11 + JUMBF label
found.append(("APP11/C2PA", length))
if marker == 0xE1 and b"DigitalSourceType" in segment: # APP1 XMP
found.append(("XMP/DigitalSourceType", length))
if marker == 0xDA: # start of scan, image data follows
break
i += 2 + length
return found
print(find_c2pa_jpeg(sys.argv[1]) or "No AI metadata markers found")
Reading PNG text chunks in the browser
Stable Diffusion prompts are plain tEXt chunks, so a few lines of JavaScript can read them client-side:
async function readPngText(file) {
const buf = new DataView(await file.arrayBuffer());
const out = {};
let p = 8; // skip PNG signature
while (p < buf.byteLength) {
const len = buf.getUint32(p);
const type = String.fromCharCode(...new Uint8Array(buf.buffer, p + 4, 4));
if (type === "tEXt") {
const bytes = new Uint8Array(buf.buffer, p + 8, len);
const [key, ...val] = new TextDecoder("latin1").decode(bytes).split("\0");
out[key] = val.join("\0");
}
if (type === "caBX") out.c2pa = `${len} bytes`;
p += 12 + len; // length + type + data + CRC
}
return out; // e.g. { parameters: "a cat, 8k ... Steps: 30, Seed: 1234" }
}
Removing a chunk is just skipping it when you rebuild the file. Because you're copying the image data chunks byte for byte, there's no re-encoding and no quality loss.
Gotchas I hit while building this
- HEIC and AVIF store metadata in ISOBMFF boxes, not segments, so you need a box parser.
- Some apps duplicate the IPTC field inside both XMP and the C2PA manifest. Strip one and the label still appears.
-
Thumbnails embedded in EXIF can contain the unedited original. Strip
IFD1too if privacy matters. - Pixel watermarks (Google SynthID, TikTok's watermarking) are not metadata. No metadata tool removes them, and that's by design.
A note on responsible use
C2PA exists for good reasons: provenance helps people spot fakes. Stripping it makes sense for false positives (real photos with a minor AI edit) and privacy (GPS, serial numbers, leaked prompts). If content is genuinely AI-generated, platforms and laws like the EU AI Act may still require you to disclose it.
Want the no-code version?
If you just need clean files, AI Flag Remover does all of the above in the browser (JPG, PNG, WebP, HEIC, AVIF), shows which AI flags it found, and re-checks the output. There's also a free AI image metadata checker if you only want to inspect.
What other metadata quirks have you run into? Let me know in the comments.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes ā full credit and traffic to the original publisher.