AI Art & Prompts • • 12 min read • ✓ Fact-Checked by Provenance Engineering Staff

PNG Chunk Internals: Decoding and Scrubbing tEXt/iTXt/zTXt Prompts from ComfyUI & Stable Diffusion

PNG Chunk Internals: Decoding and Scrubbing tEXt/iTXt/zTXt Prompts from ComfyUI & Stable Diffusion

Executive Summary & The Open-Source AI Metadata Landscape

While commercial generative AI platforms (OpenAI DALL-E 3, Adobe Firefly, Google Imagen) rely on JPEG APP11 C2PA manifests, the open-source and local AI art community—centered around Stable Diffusion, SDXL, ComfyUI, Fooocus, NovelAI, and Automatic1111—operates almost exclusively in the PNG (Portable Network Graphics) file format.

PNG is favored by digital artists because it supports lossless compression and true 8-bit/16-bit alpha channel transparency. However, few creators realize that when they click "Save Image" inside a ComfyUI workflow or Automatic1111 WebUI, the generator does not merely save visual pixels; it injects the creator's entire creative history into the file header. This includes the full text of positive prompts, negative prompts, random seed numbers, sampler names, CFG scales, LoRA model filenames, checkpoint hashes, and in the case of ComfyUI, the complete JSON node graph detailing every custom node and path on the creator's local hard drive.

In this technical breakdown, we dissect the internal chunk architecture of PNG files, examine how AI generation parameters are embedded inside ancillary text chunks, and demonstrate how to scrub them with zero pixel re-encoding and zero loss of alpha transparency.


Anatomy of a PNG File: Critical vs. Ancillary Chunks

The PNG file format (standardized under ISO/IEC 15948) possesses one of the cleanest and most modular architectures in digital media. Every PNG file begins with an immutable 8-byte signature: 89 50 4E 47 0D 0A 1A 0A (‰PNG  )

Following this signature, the entire file is structured as a continuous series of self-contained chunks. Each chunk consists of four sequential fields: 1. Length (4 Bytes, Big-Endian): Specifies the number of data bytes in the chunk's payload. 2. Chunk Type (4 Bytes, ASCII): Four case-sensitive ASCII letters identifying the chunk's function. 3. Chunk Data (Length Bytes): The actual payload data. 4. CRC (4 Bytes): A Cyclic Redundancy Check calculated over the Chunk Type and Chunk Data fields to verify data integrity.

The PNG specification divides chunks into two fundamental categories based on the capitalization of the first letter: - Critical Chunks (Uppercase first letter): Required for standard decoders to render the image. - IHDR (Image Header): Width, height, bit depth, color type, compression method, filter method, and interlace method. Must be the first chunk. - PLTE (Palette): Required for indexed-color images. - IDAT (Image Data): The zlib-deflated visual pixel stream. Multiple consecutive IDAT chunks store the compressed scanlines. - IEND (Image Trailer): A 0-byte payload chunk marking the end of the PNG stream. Must be the final chunk. - Ancillary Chunks (Lowercase first letter): Optional metadata chunks that standard image viewers can safely ignore without affecting pixel display. - tEXt: Uncompressed key-value text pairs (Latin-1 encoding). - zTXt: Deflate-compressed key-value text pairs. - iTXt: International UTF-8 text strings (compressed or uncompressed), containing language tags and keywords. - pHYs: Physical pixel dimensions and aspect ratio. - eXIf: Standard camera EXIF data. - caBX: C2PA Content Credentials manifest in PNG format.


How ComfyUI & Stable Diffusion Exploit Text Chunks

Open-source AI image generators take advantage of tEXt and iTXt ancillary chunks to store workflow reproducibility data.

The Automatic1111 / WebUI Format

Automatic1111 writes a single tEXt chunk with the keyword parameters:

`` Keyword: "parameters" Text: "masterpiece, best quality, cinematic portrait of a cybernetic engineer in Tokyo... Negative prompt: low quality, blurry, deformed hands... Steps: 28, Sampler: DPM++ 2M Karras, CFG scale: 7, Seed: 3849102948, Size: 1024x1024, Model hash: e6415c4c79, Model: juggernautXL_v9" ``

The ComfyUI Format

ComfyUI takes this practice to an extreme. It writes two separate iTXt or tEXt chunks: 1. prompt: A JSON-serialized representation of every active node, its widget inputs, and connection links. 2. workflow: The complete visual UI layout of the ComfyUI workspace, including node coordinates, color themes, custom group boxes, and exact local file paths to checkpoints, controlnets, and LoRA weights on your operating system (e.g., C:/Users/Armend/ComfyUI/models/checkpoints/...).

The Privacy and Competitive Exposure

When digital artists, commercial illustrators, or game developers share these raw PNG exports online: - Commercial Prompt Leaks: Proprietary prompt engineering, custom negative prompt formulas, and proprietary LoRA trigger words are exposed in plain text to any viewer or competitor who drags the image into an inspector. - Security & Path Disclosure: Local file system usernames, directory hierarchies, and internal network drive paths stored inside the ComfyUI workflow JSON are exposed publicly. - Automated Social Flagging: Platforms that parse PNG ancillary chunks automatically identify these keywords and apply AI detection tags.


In-Browser Lossless PNG Scrubbing Algorithm

Generic cleaners fail on PNGs because converting a PNG through a canvas or converting it to JPEG destroys transparent alpha channels (turning transparent backgrounds into solid black or white) and re-compresses clean flat-color graphics.

Clear AI Label's PNG AI Metadata Scrubber operates with zero canvas redraws and zero re-compression. It parses the raw binary chunk stream byte-by-byte, copying all critical chunks (IHDR, PLTE, IDAT, IEND) and harmless rendering chunks (pHYs, gAMA, cHRM), while completely dropping tEXt, zTXt, iTXt, and caBX chunks.

Here is the architectural flow of our in-browser PNG parser:

`` [Input PNG Uint8Array] │ ▼ [Verify PNG Signature: 89 50 4E 47 0D 0A 1A 0A] │ ▼ Loop through chunks Read 4-byte Length (N) ──► Read 4-byte Chunk Type (e.g. 'tEXt') │ ├── Is Type === 'tEXt' | 'zTXt' | 'iTXt' | 'caBX'? │ ├── YES: Skip (N + 12) bytes (Length + Type + Payload + CRC) │ │ Do NOT copy to output stream. │ │ │ └── NO: Retain chunk! │ Copy Length + Type + Payload + CRC directly to output. │ Advance offset by (N + 12) until IEND chunk is reached. │ ▼ [Assemble Clean Master Uint8Array] - Alpha transparency 100% intact - IDAT pixel scanlines 100% bit-for-bit identical - Zero prompt text, zero ComfyUI JSON nodes - File size reduced by up to 500 KB of metadata bloat ``

Because the IDAT chunks containing the compressed pixel scanlines are transferred as raw byte arrays, the operation executes at memory-bus transfer speed (under 5 milliseconds for a 20-megabyte PNG) and preserves 100% of the image's original alpha transparency and visual color depth.


Verification: Before and After Hex Inspection

To verify that your PNG has been cleanly scrubbed: 1. Raw File Check: Open your original ComfyUI PNG in a text editor or hex viewer. Searching for the string "class_type" or "KSampler" will immediately reveal hundreds of lines of embedded JSON code. 2. Process with Clear AI Label: Drag the PNG into PNG AI Metadata Remover. Click Clean Images. 3. Cleaned File Check: Open the downloaded Social_Ready_ PNG in the same hex editor. The "class_type", "prompt", and "parameters" strings are completely gone. The file consists solely of IHDR, pHYs, IDAT, and IEND.


Frequently Asked Questions (FAQ)

Does scrubbing PNG chunks reduce image resolution or color quality?

No. PNG is a lossless format. The visual pixels reside entirely inside the IDAT chunks. Clear AI Label strips only non-visual text chunks (tEXt, iTXt, zTXt). The pixel data is untouched.

Will my transparent PNG backgrounds remain transparent?

Yes. Unlike tools that convert PNGs to JPEGs (which cannot support transparency), our lossless chunk scrubber retains the PNG format, bit depth, and alpha channel transparency completely intact.

Can I still load the cleaned PNG back into ComfyUI to retrieve the workflow?

No. Once the prompt and workflow chunks are stripped, the node graph is permanently removed from that specific file. We recommend always keeping an unstripped master copy in your private archive for workflow editing, and using Clear AI Label to generate clean public distribution copies.


Anatomy of Deflate Compression in `zTXt` and `iTXt` Chunks

When inspecting PNG ancillary chunks, understanding the difference between tEXt, zTXt, and iTXt is crucial for both security auditing and lossless metadata stripping:

  1. tEXt (Latin-1 Text):
    Structure: Keyword (1-79 bytes) + Null Separator (0x00) + Text String.
    Entirely uncompressed. Easy to inspect in simple text viewers.
  2. zTXt (Compressed Text):
    Structure: Keyword + Null Separator + Compression Method (0x00 = Deflate) + Compressed Datastream.
    Employs standard zlib/deflate compression. Used by some WebUI extensions when prompt lengths exceed 1,000 characters.
  3. iTXt (International Text):
    Structure: Keyword + Null Separator + Compression Flag (0 = uncompressed, 1 = compressed) + Compression Method + Language Tag + Translated Keyword + Text.
    Encoded in UTF-8. This is the primary chunk utilized by modern ComfyUI installations to embed extensive multi-node workflows.

Deep-Dive into ComfyUI Workflow JSON

In a typical ComfyUI iTXt chunk, the serialized JSON code looks like this:

``json { "last_node_id": 24, "nodes": [ { "id": 4, "type": "CheckpointLoaderSimple", "pos": [26, 375], "size": [315, 98], "flags": {}, "order": 0, "mode": 0, "inputs": [], "outputs": [{"name": "MODEL", "type": "MODEL", "links": [1]}], "widgets_values": ["sd_xl_base_1.0.safetensors"] }, { "id": 6, "type": "CLIPTextEncode", "pos": [384, 192], "size": [422, 164], "widgets_values": ["cinematic award-winning photography, 8k resolution, dramatic lighting, sharp focus"] } ] } ``

Because ComfyUI embeds the complete canvas state, any private proprietary techniques—such as custom ControlNet weight thresholds, IP-Adapter reference images, or custom Python script names—are exposed in plain text.

By implementing our pure TypedArray chunk excision algorithm, Clear AI Label drops these chunks at the binary level. The visual pixel stream inside IDAT chunks is never touched, decompressed, or altered. The file size drops significantly, all commercial secrets are secured, and social media platforms receive a clean, unencumbered PNG file.

⚡ 100% Client-Side In-Browser Utility

Inspect & Strip AI Metadata in 1 Click

Remove C2PA manifests, XMP markers, and PNG generation tags directly inside your browser. Zero server uploads. Batch process up to 30 files for free.

🛡️

Clear AI Label Editorial & Provenance Engineering Team

Verified Technical Guide

Our engineering team researches ISO/IEC 19566-5 JUMBF (C2PA) standards, Adobe XMP schemas, binary TIFF EXIF structures, and social media upload compliance to build transparent, privacy-first browser utilities. Read our editorial standards →

Related AI Art & Prompts Guides

Further technical reading on digital provenance, C2PA headers, and platform upload workflows.

View All 175 Guides →