How JPEG, PNG, WebP and GIF store metadata (and how lossless removal works)
By ExifZero Engineering · Updated
Short answer: Image formats do not mix metadata into pixel bytes. JPEG wraps metadata in APP1–APP15 and
COM marker segments, PNG uses named chunks such as eXIf, tEXt, iTXt and caBX,
WebP uses RIFF chunks paired with header bitflags in VP8X, and GIF uses extension blocks (0x21 0xFE and
0x21 0xFF). Cutting out those non-image blocks and updating container headers leaves the compressed pixel stream byte-for-byte
unchanged.
A common misconception about metadata removers is that every cleaner has to open the picture, redraw it onto an invisible canvas, and save a brand new file. Canvas re-saving works, but it throws away compression quality on JPEGs, bloats lossless graphics, and frequently discards the ICC color profile. Knowing how the underlying file containers are laid out makes it obvious why direct block editing is both faster and cleaner.
Visual layout: JPEG segments vs. PNG chunks
Inside a JPEG or PNG, image pixels and metadata sit in consecutive, self-delimiting blocks. A container-level stripper walks each block's length prefix, copies the blocks needed to decode colors and pixels, and skips the rest.
1. JPEG marker segments
A JPEG file begins with Start of Image (0xFFD8, SOI) and runs through variable-length marker segments until End of Image
(0xFFD9, EOI). Each metadata segment starts with a 2-byte marker followed by a 2-byte big-endian length:
APP0(0xFFE0): Usually carries aJFIF\0header needed by older decoders (kept), or aJFXX\0extension thumbnail (stripped).APP1(0xFFE1): The workhorse metadata slot. If its payload begins withExif\0\0, it contains a miniature TIFF file with IFD0, ExifIFD, GPS IFD and often an embeddedIFD1thumbnail. If it begins withhttp://ns.adobe.com/xap/1.0/\0, it carries XMP XML (plus Extended XMP chunks if XMP exceeds 64 KB).APP2(0xFFE2): Holds either anICC_PROFILE\0color profile (kept when "Keep color profile" is checked) orMPF\0Multi-Picture Format pointers to secondary depth maps or HDR gain maps (stripped).APP11(0xFFEB): Standard home for C2PA Content Credentials stored as JUMBF boxes taggedJP. Large C2PA manifests split across multipleAPP11segments tied together by an instance number and sequence counter.APP13(0xFFED): LegacyPhotoshop 3.0\0image resource blocks carrying IPTC-IIM captions, bylines and locations.COM(0xFFFE): Free-text comment block where tools like Stable Diffusion WebUI sometimes write generation parameters into JPEGs.DQT,DHT,SOF0/SOF2,SOS: Quantization tables, Huffman tables, frame geometry and entropy-coded scan data — kept byte for byte.
If any bytes exist after EOI, decoders ignore them, yet file scanners and ExifZero's File structure tab flag them as a
trailer block — catching Android Motion Photos (an MP4 clip appended after EOI) and hidden payloads.
Real before/after block map (JPEG)
Open any photo in ExifZero and switch to the File structure tab to read this table live. On a typical phone or AI-tagged JPEG, cleaning shrinks the block list to the bare decoding skeleton:
BEFORE CLEANING (1,428,912 bytes)
0 .. 2 SOI Image data
2 .. 20 APP0 JFIF header (Image structure)
20 .. 16840 APP1 EXIF (GPS, device serial, IFD1 thumbnail) -> DROP
16840 .. 21104 APP1 XMP (creator, history, DigitalSourceType) -> DROP
21104 .. 24260 APP2 ICC color profile -> KEEP (optional)
24260 .. 89412 APP11 JUMBF (C2PA Content Credentials) -> DROP
89412 .. 1428910 DQT/DHT/SOF0/SOS/EOI (compressed pixel scan) -> KEEP
AFTER CLEANING (1,340,180 bytes — 88,732 bytes removed, 0 pixels altered)
0 .. 2 SOI Image data
2 .. 20 APP0 JFIF header
20 .. 52 APP1 Minimal EXIF (Orientation = 6 only, if rotated)
52 .. 3208 APP2 ICC color profile
3208 .. 1340180 DQT/DHT/SOF0/SOS/EOI (identical scan bytes) 2. PNG chunks and CRC-32 checksums
PNG files start with an 8-byte signature followed by four-part chunks: a 4-byte length, a 4-character ASCII type, the payload, and a 4-byte CRC-32
checksum covering the type and payload. The case of the first letter tells decoders whether a chunk is critical (IHDR,
PLTE, IDAT, IEND) or ancillary.
Metadata hides in ancillary chunks: tEXt (uncompressed Latin-1), zTXt (zlib-compressed), and iTXt
(UTF-8, optionally compressed — used by Adobe XMP under key XML:com.adobe.xmp and by ComfyUI/A1111 for prompts). Modern PNGs also
carry eXIf for binary EXIF, tIME for modification timestamps, and caBX for C2PA manifests. Color-rendering
chunks such as sRGB, gAMA, cHRM, cICP and iCCP control how colors map to your
monitor and contain no personal data. When preserving rotation on a PNG, any new minimal eXIf chunk inserted right after
IHDR must calculate an exact CRC-32 trailer or strict PNG decoders will reject the file.
3. WebP RIFF chunks and the VP8X header pitfall
WebP wraps image and metadata inside a Little-Endian RIFF container: 12-byte header (RIFF + total file size minus 8 + WEBP)
followed by padded chunks. Image data sits in VP8 (lossy), VP8L (lossless), or animation frames (ANIM,
ANMF). Metadata sits in EXIF, XMP , and C2PA, with color profiles in ICCP.
Here is the trap that breaks naive WebP cleaners: whenever a WebP carries ICC, EXIF, XMP, alpha or animation, its first chunk is an extended
header named VP8X containing bitflags (0x20 for ICC, 0x08 for EXIF, 0x04 for XMP). If a script
deletes the EXIF or XMP chunk without clearing those bits in VP8X — and without rewriting the 32-bit RIFF
size at byte offset 4 — Chrome, macOS Preview and libwebp can treat the file as corrupt.
4. GIF extensions
GIF87a and GIF89a store headers, color tables, frame descriptors and LZW-compressed frames, alongside extension blocks introduced by
0x21. Label 0xFE stores plain-text comments (where some generators write tool strings), while label 0xFF
(Application Extension) handles both animation looping (NETSCAPE2.0) and Adobe XMP (XMP DataXMP) or ICC profiles
(ICCRGBG1012). Dropping 0xFE and XMP DataXMP while preserving loop extensions leaves animated GIFs fully
playable.
Lossless block stripping vs. canvas re-encoding
| Property | Lossless block stripping | Browser canvas re-encode |
|---|---|---|
| Pixel values | Bit-for-bit identical | Recompressed (generation loss on JPEG) |
| ICC color profile | Kept optionally without converting pixels | Typically stripped or clipped to sRGB |
| Animation (GIF / WebP) | Preserved across all frames | Collapsed to a single static frame |
| File size | Shrinks strictly by removed metadata bytes | Can double or triple on clean PNGs/JPEGs |
| Supported formats | JPEG, PNG, WebP, GIF | Needed for HEIC, AVIF, TIFF (no native JS muxer) |
Frequently asked questions
Why does removing EXIF with ExifZero keep image quality 100% identical?
Because JPEG, PNG, WebP and GIF store metadata in separate labelled segments or chunks outside the compressed pixel stream. ExifZero copies the image-data blocks byte for byte and omits the metadata blocks, so pixels are never decoded or recompressed.
Why does a cleaned JPEG still have a small APP1 segment when Keep rotation is checked?
Phone cameras often store pixels sideways and rely on an EXIF Orientation tag (1 through 8) to tell viewers which way is up. When Keep rotation is enabled and orientation is greater than 1, ExifZero writes a fresh, minimal 1-tag TIFF/EXIF block containing only that orientation integer — zero camera, date or GPS tags.
Why can’t ExifZero strip HEIC or AVIF without re-encoding?
HEIC and AVIF use complex ISO Base Media File Format (ISOBMFF) box trees with item property tables and offsets. Browsers can decode them via native OS codecs onto a canvas, so ExifZero converts them to a clean high-quality JPEG and labels them “re-encoded” in the interface.
What is “Data after image end” in the File structure tab?
Some cameras and Android phones append extra data — most commonly an MP4 Motion Photo clip — after the JPEG End of Image marker (0xFFD9) or PNG IEND chunk. Image decoders stop at the end marker, so that hidden trailer often goes unnoticed until a container scanner reads the full byte length.