MetaPurge

Remove metadata from WebP: RIFF chunks, VP8X flags and sizes

WebP is a RIFF container, which makes it tidy in one way and awkward in another. Chunks are easy to remove, but the file-level size field at byte four has to be corrected or the result is malformed.

By Rajat Malik Updated 8 min read

WebP is a container around a compression format, not a compression format with a header. The container is RIFF, the same family used by WAV and AVI, and the image data is one of two bitstreams: VP8 for lossy, VP8L for lossless. Metadata lives in separate chunks, so removing it never requires decoding the bitstream.

The RIFF container

The first twelve bytes are fixed. The ASCII tag RIFF, a four-byte little-endian size, then the ASCII tag WEBP. Everything after that is a sequence of chunks, and every integer in the file is little-endian — the reverse of JPEG and PNG, which use network byte order throughout.

Each chunk is a four-byte FourCC, a four-byte little-endian payload size, the payload, and a single padding byte if the payload length is odd. The pad byte is not counted in the chunk's size field, but it does occupy space in the file.

There are two layouts. A simple file is one VP8 or VP8L chunk and nothing else. An extended file starts with VP8X, which carries feature flags and the canvas size, then optional chunks for colour profile, animation, alpha, EXIF and XMP.

Reading the VP8X flags

VP8X has a ten-byte payload: one byte of flags, three reserved bytes that must be zero, then the canvas width and height as 24-bit little-endian values, each stored minus one. The flags tell a decoder which optional chunks to expect.

BitValueMeans
10x02Animation present
20x04XMP chunk present
30x08EXIF chunk present
40x10Alpha present
50x20ICC profile present

Remove an EXIF chunk and you must clear bit 3, otherwise the header claims a chunk that is not there. Behaviour in that case depends on the decoder: some ignore the mismatch, some warn, and some treat the file as damaged. Clearing the bit is part of a correct strip, not an optional tidy-up.

EXIF, XMP and ICCP chunks

Three chunks carry the metadata you are likely to care about. The FourCC for XMP is XMP followed by a space, which is easy to miss when reading a hex dump.

The EXIF chunk holds a TIFF block in the same IFD structure used by JPEG, with GPS, device details, timestamps and orientation. In practice writers store the raw TIFF block without the Exif identifier that JPEG prepends, but some include it, so a parser should check for both.

XMP holds an RDF/XML packet, which can include edit history, creator details, rights statements and a second copy of the GPS coordinates. ICCP holds an uncompressed ICC colour profile.

A fourth container-level field is worth knowing about: ANIM describes an animation loop, and each frame lives in an ANMF chunk that wraps its own image sub-chunks. Metadata stripping must leave those alone; a frame is not a metadata chunk even though it has its own header.

Fixing the RIFF size

The size field at bytes 4 to 7 is the total file length minus eight. It is the one number that has to change when chunks are removed, because it is the only file-level length in the format. Everything else is per-chunk and stays valid as long as you delete whole chunks.

The arithmetic is easy to get wrong by eight. Take a 12,000-byte file: its size field reads 11,992. Remove an EXIF chunk of 602 bytes — eight bytes of header and 594 bytes of payload — and the file becomes 11,398 bytes. The new field must read 11,390, not 11,398.

If you trim a chunk instead of removing it, two more things change. The chunk's own size field must be updated, and the padding byte must be added or removed to keep the payload length even. For an EXIF chunk reduced to a single orientation entry, that means recalculating the TIFF block's internal offsets as well.

WebP has no per-chunk checksum. PNG has a CRC-32 on every chunk; RIFF does not, so there is nothing to recompute after a deletion. The size field is the entire bookkeeping burden.

A wrong size can still open Some decoders read chunks until they hit the declared end, so an over-long size field can make a viewer ignore trailing chunks, and a short one can make it stop mid-chunk. The file may look fine in one browser and fail in another. Validate the size field after every strip.

Lossy, lossless and what a strip touches

VP8 is the lossy bitstream. It is an intra-frame codec, related to the video codec of the same name, and it quantises like JPEG does. VP8L is lossless, using spatial prediction and entropy coding, and reconstructs the exact RGB values.

A lossy file with transparency carries a separate ALPH chunk alongside the VP8 data. Animated files use ANIM plus one ANMF per frame. None of these are affected by metadata stripping, because the strip never decodes anything.

The trap is a converter, not a stripper. If a tool asks for a quality level while removing metadata, it is re-encoding: decoding the old bitstream and producing a new one. A lossless WebP put through a lossy encoder loses exactness permanently. A byte-level strip has no quality setting at all, which is the tell.

Keeping colour and orientation

Keep ICCP and leave bit 5 set. Wide-gamut WebP files are uncommon compared with PNG and JPEG, but they exist, and an untagged one is interpreted as sRGB, which shifts colour. Keep ALPH and the animation chunks for the obvious reason: they are part of the image, not part of the metadata.

Orientation is less clear-cut in WebP than in JPEG. The format allows an EXIF chunk, and that chunk can carry tag 0x0112, but whether a given application applies it to a WebP image varies. Browsers that honour EXIF orientation generally do so for WebP as well, but image pipelines and thumbnailers are less consistent.

If you need the file to display upright everywhere, the robust option is to rotate the pixels once and store the image in its display orientation, rather than shipping a tag that half your viewers may ignore. If you keep the tag, keep a minimal EXIF block with only orientation — no GPS, no serials.

For comparison, the PNG walkthrough covers a container with checksums, and the JPEG walkthrough covers one with progressive scans. The profiles and orientation guide explains why those two survive a strip on purpose.

See what your photos are carrying

Drop an image in. MetaPurge lists every tag, then rewrites the file without touching a pixel.

Open the metadata remover

Where to go next

Rajat Malik Frontend architect and the author of MetaPurge. Builds browser tools that keep files on the device, and writes about the parts of the web that leak by default. rajatmalik.dev