Sign In

How EXIF UserComment & PNG Chunks Preserve Generation Provenance

0

Nov 15, 2026

tool guide
How EXIF UserComment & PNG Chunks Preserve Generation Provenance

# How EXIF UserComment & PNG Chunks Preserve Generation Provenance

"Does this image have metadata?" is not a yes/no question. Generation provenance can live in at least four different places depending on the file format and the generator that wrote it. This guide maps each location, shows how to read them in Python, and explains how to inject complete provenance that survives re-uploads.

---

## 1. The map: where metadata actually lives

| Format | Location | Written by | Survivability |

| :--- | :--- | :--- | :--- |

| PNG | `tEXt` / `iTXt` chunk named `parameters` | A1111, Forge, ComfyUI | Survives re-uploads to most platforms; stripped by some chat apps |

| PNG | `tEXt` chunk `Civitai resources` | injectors / site export | Same as above |

| JPEG | EXIF tag `0x9286` (UserComment) | A1111 JPEG export | Fragile — many tools rewrite EXIF |

| WebP | EXIF UserComment or XMP | A1111 / ComfyUI WebP | Medium |

| Any | Sidecar `.txt` / YAML | ComfyUI workflows, manual | Only as durable as your folder organization |

The PNG `tEXt` chunk is the most reliable carrier: it sits inside the file's chunk structure, survives lossless recompression, and is exactly what Civitai's upload pipeline parses to fill the generation-data panel.

---

## 2. Anatomy of a PNG `parameters` chunk

A PNG is a sequence of chunks: `IHDR`, then optional ancillary chunks (`tEXt`, `iTXt`, `zTXt`), then `IDAT`, then `IEND`. A `tEXt` chunk is:

```

[length: 4 bytes][type: "tEXt"][keyword\0text][CRC32: 4 bytes]

```

So `parameters` + your A1111 string becomes a first-class binary citizen of the file. Reading it in Python:

```python

from PIL import Image

with Image.open("output.png") as im:

im.load()

params = (im.text or {}).get("parameters")

if params:

print(params)

else:

print("No parameters chunk found")

```

Writing it — with a fresh, correct CRC — is equally direct:

```python

from PIL import Image

from PIL.PngImagePlugin import PngInfo

meta = PngInfo()

meta.add_text("parameters", a1111_parameters_string)

meta.add_text("Civitai resources", civitai_resources_json)

with Image.open("output.png") as im:

im.load()

im.save("output_tagged.png", pnginfo=meta)

```

Three implementation details that bite people:

1. **Recompute CRC.** Hand-edited chunks with stale CRCs are rejected by strict parsers (and by browsers in some contexts). PIL handles this for you; raw byte surgery does not.

2. **`im.load()` before `im.save()`.** If you save from a lazily-opened handle, you can silently propagate a truncated read.

3. **Keep the keyword ASCII.** `tEXt` keywords are 1–79 bytes of Latin-1; the *value* can be UTF-8 text in practice, but the keyword `parameters` itself must stay plain.

---

## 3. EXIF UserComment (0x9286) in JPEG and WebP

JPEGs have no chunk structure, so A1111 falls back to the EXIF `UserComment` field. The layout quirk: the value is typically prefixed with an 8-byte charset header — `UNICODE\x00` — before the actual text.

```python

from PIL import Image

with Image.open("photo.jpg") as im:

exif = im.getexif()

raw = exif.get(0x9286, b"")

text = raw.decode("utf-8", errors="ignore") if isinstance(raw, bytes) else str(raw)

if text.startswith("UNICODE\x00"):

text = text[8:]

print(text)

```

If the text contains `Steps:` and `Seed:`, you're looking at A1111-format provenance.

**Why you should convert JPEG → PNG before publishing:** EXIF is routinely rewritten or dropped by editors, chat apps, and some CDNs. A PNG `tEXt` chunk rides through the same pipelines far more often intact. Our standard pipeline is: *generate → inject → convert to PNG → verify hashes → publish.*

---

## 4. Verification: hashes that platforms actually use

Civitai's **AutoV2** hash is simply the first 10 hex characters of the file's SHA-256, uppercased. It lets the site match your file against published resources regardless of filename:

```python

import hashlib

def autov2(path: str) -> str:

h = hashlib.sha256()

with open(path, "rb") as f:

for block in iter(lambda: f.read(65536), b""):

h.update(block)

return h.hexdigest()[:10].upper()

```

A complete pre-upload audit checks:

- `parameters` chunk present (PNG) or UserComment present (JPEG/WebP)

- `Steps:`, `Sampler:`, `Seed:`, `Model:` / `Model hash:` all present in the text

- `Civitai resources` chunk parses as JSON and lists every checkpoint/LoRA used

- AutoV2 recorded for the manifest

---

## 5. Provenance is also your protection

Embedded generation data isn't only for reviewers. When your image circulates:

- The `parameters` chunk travels with it and documents your prompt craft.

- Linked resource IDs drive downloads back to models you used — and, for resources you publish, back to you.

- If your work is ever reposted without credit, the embedded lineage is timestamped, hash-verifiable evidence of origin.

Treat metadata as part of the artwork. Ship it complete, verify it mechanically, and never rely on filenames or sidecars alone.

*Companion article: Mastering Image-to-Video on Civitai — Clean PNG Metadata & Provenance.*

0

Comments