What Is a WebP File? The Image Format Google Made, and How to Check, Fix and Convert One
A WebP file is an image file that Google made for smaller pictures on the web. Four readers agreed on only 17 of the 21 damaged copies we made of one. Jump to your question below, or work through it in order.
What Is a WebP File? The image file Google made for smaller pictures
Short answer
A WebP file is an image file that Google developed to make pictures smaller on the web. It can store a lossy picture, a lossless picture, transparency and a short animation. The file is a RIFF container, and the first 12 bytes spell RIFF, a size and WEBP.
We tested 194 public WebP files with four readers, dwebp, Pillow, ImageMagick and ffmpeg. All four passed 178 of them. The 16 animated files passed in Pillow and ImageMagick only. We then damaged one WebP file in 21 ways, and the four readers agreed on 17 copies.
To open one, see the open steps. To check one, see the check steps. If your WebP file will not open, begin with the eight causes.
A WebP file is an image file. It stores one picture or a short animation in a RIFF container. Google developed the format, and the file can use lossy or lossless compression and store transparency.
Picture a friend who sends photo and says it will not open in an old editor. You save it and see a normal picture in your browser. Picture a second file that every tool refuses. Both end in .webp, and only the bytes inside show which one is sound.
Wikipedia says Google developed WebP and announced it on 30 September 2010. The format stores a lossy picture with VP8 video coding, or a lossless picture with its own method. Both modes can store transparency, and an animation can have many frames.
A WebP file lives in a RIFF container. RFC 9649 describes that container, and the file starts with the letters RIFF, a size and the letters WEBP. Then come chunks. Every chunk has a four letter name and a size.
Wikipedia gives a side a limit of 16,383 pixels. Browsers read WebP, and Wikipedia lists Chrome, Firefox and Safari. Support came in stages, and we tested no editor. People still ask how to open a WebP file.
IANA lists image/webp with the ending .webp. Our file command printed the same type for our example. The IANA page names RFC 9649 as the reference and lists James Zern as the contact.
Where our WebP files come from
We read 194 files from 5 public projects. The largest is libwebp-test-data with 131 files. sharp adds 24, image-webp 23, Pillow 14 and libvips 2. All 194 end in .webp.
They are test files, and many exist to test readers on odd cases. They are 28 to 13,968,454 bytes long and 21,782,578 bytes in total, and the median is 11,398 bytes. All 194 passed webpinfo with the words No error detected.
So this page studies how readers treat the WebP layout, and not a sample of pictures from everyday downloads. We also made one file of 238 bytes and damaged it in 21 ways. We opened nothing in a browser or an editor.
WebP file facts at a glance
| Property | Value |
|---|---|
| Meaning | Web picture. It stores a lossy or lossless image, and it can store transparency and frames. |
| Ending | .webp, per IANA. |
| Maker | Google developed it and announced it on 30 September 2010, per Wikipedia. |
| Container | RIFF. The first 12 bytes spell RIFF, a 4 byte size and WEBP. |
| Kinds | VP8 lossy, VP8L lossless and VP8X extended. 82, 54 and 58 of our files, and 16 of the 58 are animated. |
| Type | image/webp, per IANA. The file command printed the same type for our example. |
| Limits | 16,383 pixels on a side, per Wikipedia. |
| Our tests | 194 files, 21 damaged copies, 4 readers, 1 repair route and a script of 34 lines. |
Wrong page? A PNG file starts with the bytes 89 50 4E 47, and a JPG file starts with FF D8. See how WebP, PNG, JPG and GIF differ.
Which Kind of WebP File Do You Have? Four kinds, and byte 12 names the kind
Four kinds name the kind of a WebP file. In our 194 files, 82 are lossy VP8, 54 are lossless VP8L, 42 are extended stills and 16 are animated. All of them end in .webp, so the ending names none of the kinds.
Look at the chunk name at byte 12 and follow the figure. We tested all four kinds with four readers. The animated kind is the one that splits them, because dwebp and ffmpeg refused all 16 animated files.
The four kinds in detail
| Kind | Files and results |
|---|---|
| VP8 with a space | 82 files. This is a lossy file. dwebp, Pillow, ImageMagick and ffmpeg passed all 82. |
| VP8L | 54 files. This is a lossless file. All four readers passed all 54. |
| VP8X, no animation | 42 files. This is an extended still. All four readers passed all 42. |
| VP8X with frames | 16 files. This is an animation. Pillow and ImageMagick passed all 16, and dwebp and ffmpeg passed none. |
Start with the first bytes
Open the file in a hex viewer, or use xxd -l 32 example.webp on Linux or Mac. Our file starts with 52 49 46 46, the letters RIFF. Bytes 8 to 11 say WEBP, and bytes 12 to 15 say VP8 with a space.
xxd -l 32 example.webp
00000000: 5249 4646 e600 0000 5745 4250 5650 3820 RIFF....WEBPVP8
00000010: da00 0000 d006 009d 012a 4000 3000 3e6d .........*@.0.>m
file -b example.webp
RIFF (little-endian) data, Web/P image, VP8 encoding, 64x48, Scaling: [none]x[none], YUV color, decoders should clamp
file -b --mime-type example.webp
image/webp
The file command reads the bytes and not the ending. It printed RIFF (little-endian) data first for all 194 files. Our example added Web/P image, VP8 encoding and 64x48, so the command also read the size.
webpinfo ships with libwebp and prints the chunks. For our example it says Chunk VP8 at offset 12, Width 64, Height 48, Format Lossy and No error detected.
Not sure your file is a WebP file at all? Check it with our script.
What Is Inside a WebP File? A RIFF header and a list of chunks
A WebP file is a RIFF header and a list of chunks. Our example is 238 bytes long. It has one VP8 chunk of 218 bytes, and the RIFF size says 230, which is the file size minus 8.
We looked inside a WebP file because its layout explains every result later on this page. We made example from a 64 by 48 gradient with cwebp -q 80. The first 32 bytes already show the header, the chunk name, the sizes and the start code.
xxd -l 32 example.webp
00000000: 5249 4646 e600 0000 5745 4250 5650 3820 RIFF....WEBPVP8
00000010: da00 0000 d006 009d 012a 4000 3000 3e6d .........*@.0.>m
Read the first line. 5249 4646 is RIFF. e600 0000 is 230 in little endian. 5745 4250 is WEBP, and 5650 3820 is VP8 and a space. The second line starts with the chunk size da00 0000, which is 218.
The parts, one by one
The size counts the bytes after the first 8. The RFC size rules say the size is little endian and below 4 GiB. A chunk has a four letter name and a 32 bit size, and an odd size gets one zero byte of padding.
In the VP8 chunk, three bytes make the frame tag. Then come the start code 9d 01 2a, a 16 bit width and a 16 bit height. Ours says 0x0040 and 0x0030, so 64 by 48.
What every part stores
| Part | What it stores |
|---|---|
| RIFF tag | The letters RIFF at bytes 0 to 3. Copy A1 changes the first letter to X, and all four readers refused it. |
| RIFF size | The file size minus 8. Ours says 230. Copy A3 adds 100, and all four readers refused it. |
| WEBP tag | The letters WEBP at bytes 8 to 11. Copy A2 changes them to WEBX, and all four readers refused it. |
| Chunk name and size | VP8 with a space and 218 in ours. Copy B6 sets the size to 1000, and all four readers refused it. |
| Start code | The bytes 9d 01 2a at byte 23. Copy C4 changes the last one, and all four readers refused it. |
| Width and height | Two 16 bit numbers at bytes 26 and 28. Copy C5 sets the width to 65, and ffmpeg returned a 65 by 48 image. |
| Other chunks | Extended files add VP8X, and can add ICCP, ANIM, EXIF and XMP chunks, per RFC 9649. Ours has none. |
What the sources say
The RFC layout section describes three layouts. A simple lossy file has one VP8 chunk. A simple lossless file has one VP8L chunk. An extended file starts with VP8X and can add color profiles, frames and metadata.
We read the layout from our own files and from RFC 9649 and Wikipedia. We did not read the security section of the RFC, so we make no security claim from it.
The map is small. Our script checks the RIFF tag, the sizes, the start code and the picture size. It cannot see inside the compressed picture, so a flipped bit can pass it, as the 21 copies show.
What Did We Find in 194 Test WebP Files? Four readers, and animation split them
We read 194 public test files with four readers and a 34 line script. dwebp and ffmpeg passed 178, and Pillow and ImageMagick passed all 194. All four passed 178 files, and none failed in all four.
All 194 files come from 5 public projects, so this is a study of those projects and not of pictures in general. Many files exist to test readers. A pass means exit code 0 and a decoded image with a width and height above 0.
Readers were dwebp 1.3.2, Pillow 12.3.0, ImageMagick 6.9.12 and ffmpeg 6.1.1, all on Linux. We tested every file alone, in a fresh folder. dwebp, Pillow and ImageMagick all use libwebp, so their answers are not independent.
| Test | Result |
|---|---|
| dwebp 1.3.2 | Passed 178 files and refused 16. The 16 are the animated files, and it said UNSUPPORTED_FEATURE for them. |
| Pillow 12.3.0 | Passed all 194 files. It read frame 0 of the 16 animated files. Its libwebp is 1.6.0. |
| ImageMagick 6.9.12 | Passed all 194 files. It read frame 0 of the 16 animated files. Its libwebp is 1.3.2. |
| ffmpeg 6.1.1 | Passed 178 files and refused the same 16 animated files. |
| Our script | Printed OK for all 194 files. The check is small, and it agrees with webpinfo on every one. |
| The file command | Printed RIFF (little-endian) data first for all 194 files. |
| Sizes | 28 to 13,968,454 bytes, with a median of 11,398 and a total of 21,782,578. 43 files are under 1,000 bytes and 2 are 1,000,000 bytes or more. |
| Alpha | 74 of 194 files have an alpha channel, per webpinfo. |
Four kinds, four outcomes
82 files are lossy, 54 lossless, 42 extended stills and 16 animated. The four kinds predict how readers do. Every reader passed every file of the first three kinds. The animated kind is the only one that split them.
dwebp and ffmpeg refused all 16 animated files. dwebp printed Status: 4(UNSUPPORTED_FEATURE). On the two animated files we looked at, ffmpeg printed image data not found. Pillow and ImageMagick passed all 16 by reading frame 0.
Where the four readers split
The four readers gave one answer on 178 of 194 files, and they all passed those. They split on the other 16, which are the animated files. No file failed in all four readers, and the animated files passed in two.
So refusing an animated WebP file does not mean the file is bad. dwebp and ffmpeg could not read the frames, and the file was sound. Test an animated file with Pillow or ImageMagick before you give up.
Passing does not mean the same pixels
Of the 178 files that all four passed, every reader found the same width and height. dwebp, Pillow and ImageMagick gave the same pixels on 177. The one difference is a lossless file whose header says no alpha while its pixels still use alpha values.
For that file, dwebp with -pam kept alpha values of 0 and 255, and Pillow and ImageMagick returned opaque pixels. We did not compare ffmpeg pixels, because its color conversion differs. A pass shows a picture decoded, and not that two tools agree.
Our script on the 194 files
Our script printed OK for all 194 files, and webpinfo said No error detected for all 194. So the script has no false alarms on this set. It also cannot say more than the header says, which the damaged copies show.
Read the study with care. It shows what four open readers do with 194 files from 5 projects. A browser, an editor or a phone can be stricter or more lenient than any of them, and we had none of those. Files from other sources can differ from ours.
What Happens When a WebP File Is Damaged? 21 broken copies, and the four readers agreed on 17
We damaged one WebP file in 21 ways. The four readers agreed on 17 copies and split on 4. Our script flagged or warned on 17. Our own script restored 11 of the 19 copies that needed a repair, and all four readers returned a changed image on 2 copies.
The 21 copies come in three groups of 7. Group A changes the header, like the RIFF tag and the sizes. Group B changes the length, by cutting bytes or adding them. Group C changes the content, like bits, the start code and the picture size. Every copy changes one thing in example.
We asked three questions about every copy. Did a reader return the same image as on the original? Did our script flag it? Did one script bring back the original bytes?
Copies that split the readers
A4 takes 100 off the RIFF size, and A7 sets it to 0. dwebp, Pillow and ImageMagick refused both, and ffmpeg returned the original image. ffmpeg read both anyway, and the other three did not.
C1 flips one bit at byte 120. The three libwebp readers refused it, and ffmpeg returned a changed image. C5 sets the width to 65. The three refused it again, and ffmpeg returned a 65 by 48 image. A reader that returns a picture is not always right.
Copies every reader accepted
Two copies read the same in all four readers. B4 adds 512 zero bytes at the end, and B5 adds a text line. RFC 9649 on trailing bytes says a reader can ignore bytes after the RIFF end, and all four did.
So junk at the end of a file does not stop a reader. A strict check can still object. Our script warned on both copies, because the RIFF size no longer matches the file.
Copies every reader refused
13 copies were refused by all four readers. They are A1, A2, A3, A5, A6, B1, B2, B3, B6, B7, C3, C4 and C7. They break a tag, a size, the start code, the frame type bit or the height. The readers have no safe way to guess what a broken header meant.
The 2 copies that changed the image
C2 zeroes 64 bytes at offset 100, and C6 swaps two bytes at offsets 100 and 101. All four readers returned a changed image for both. The header was sound, so no reader could know that the picture data was wrong.
That is why a pass proves little. Our script printed OK for C2 and C6, and for C1 and C5. A script that reads the header cannot see inside the compressed picture, so a damaged picture needs a second copy of the file or a look.
Repairs that worked
Our script of 18 lines restored 13 copies byte for byte. They are A1 to A7, B4 to B7, C3 and C4. Of those, 11 needed a repair to help a reader. B4 and B5 read as the original already.
It looks for the RIFF tag and removes junk in front. It writes the tags again, fixes the chunk name, trims bytes after the chunk and sets the sizes. For a lossy file it writes the start code and clears the frame type bit. It only handles simple lossy files with one chunk.
We found no official repair command. dwebp, Pillow, ImageMagick and ffmpeg only read and convert. We did not test the repair features of any editor or browser.
What no command repaired
B1, B2 and B3 cut bytes. C1, C2, C5, C6 and C7 change bits, bytes, a width or a height. No rule shows what the original values were, so ask for the file again. Our script restored none of these 8 copies, which leaves 8 of the 19 that needed a repair.
B1 is a close call. We fixed the sizes so the file reads, and dwebp and ImageMagick then returned a changed image. We did not count it as restored.
Read the grid with care. Every copy changes one thing in one small file. Damage in the wild changes many things at once. We opened no copy in a browser, and our repairs rely on rules that fit the file we made.
What Does Our Expert Say About WebP Files? A note from Neeraj Singh on trying a second reader
Check a WebP file with two readers before you trust it. Our four readers disagreed on 4 of 21 damaged copies. ffmpeg returned a changed image for a flipped bit and gave no error.
Expert insight
“A WebP file can pass a quick test and still show the wrong picture. Our four readers agreed on only 17 of 21 damaged copies, and ffmpeg returned a changed image for a flipped bit. Compare two readers, and ask for a new file when the picture looks wrong.”
Why one reader is not enough
A reader can return a picture without an error. ffmpeg did that for C1 and C5, and all four readers did it for C2 and C6. A refusal at least warns you that something is wrong. A wrong picture does not.
If your WebP file opens in the browser you trust and the picture looks right, treat that as the best test. Use the readers on this page when it does not. Pillow and ImageMagick passed all 194 files, so they make a good pair.
Copy your WebP file before you repair it. Work on the copy and keep the original untouched. Write down its SHA-256 hash first, so you can show later that the copy came back as it was.
How Do You Open a WebP File? A browser, four readers and what we tested
A browser opens most WebP files. We also tested four readers on Linux. Pillow and ImageMagick passed all 194 files, and dwebp and ffmpeg passed 178. The 16 they refused are animated.
The table lists the ways to open a WebP file. Rows with version numbers are tools we tested on Linux. We tested no browser and no editor, and we opened nothing on Windows or macOS.
| Program | What it does |
|---|---|
| A web browser | Wikipedia lists Chrome, Firefox and Safari as readers of WebP. We opened no file in a browser, so we make no claim about one. |
| dwebp 1.3.2 | The decoder from libwebp. It passed 178 of our 194 files and refused all 16 animated files. |
| Pillow 12.3.0 | A Python library. It passed all 194 files, and it reads the frames of an animation. |
| ImageMagick 6.9.12 | A command line tool. It passed all 194 files and read frame 0 of an animation. |
| ffmpeg 6.1.1 | A command line tool. It passed 178 files and refused the 16 animated ones. |
| The file command | It read the bytes of all 194 files and printed image/webp for our example. |
| Image editors and viewers | We tested none, so we make no claim about which versions read WebP. |
Open a WebP file in a browser
If you only want to look at the picture, drag the file into a browser window. Wikipedia lists Chrome, Firefox and Safari as browsers that read WebP. Support came in stages, and we tested no editor, so we name none that fails.
If the browser shows nothing, the file can be damaged or can be another kind of file with the wrong ending. Look at the first bytes, or use our script to see what is wrong.
Open a WebP file with Python or dwebp
Three lines of Python load the file and print its size and mode. The dwebp command saves a PNG and prints what it read. These are the actual outputs for example.
from PIL import Image
im = Image.open('example.webp')
print(im.size, im.mode, im.format)
(64, 48) RGB WEBP
dwebp example.webp -o e.png
Decoded example.webp. Dimensions: 64 x 48 . Format: lossy. Now saving...
Saved file e.png
ffprobe -v error -show_entries stream=codec_name,width,height -of csv=p=0 example.webp
webp,64,48
The size 64 by 48 matches the bytes we read in the header. A reader gives you the pixels, and a viewer decides how to show them.
Open an animated WebP file
Use Pillow or ImageMagick. dwebp refused all 16 animated files with UNSUPPORTED_FEATURE, and ffmpeg refused them too. In Pillow, Image on our 3 frame test file gave n_frames of 3. webpmux -info lists the frames and their times.
What to use for every task
See the picture. Use a browser. Read the size and mode. Use Pillow. Open an animation. Use Pillow or ImageMagick, because dwebp and ffmpeg did not read our 16 animated files. Test a file that one reader refuses. Try a second reader.
Install programs from their makers. Take ffmpeg from its own site and libraries from their own pages. A free web tool receives your picture, so try the steps on this page first.
How Do You Check a WebP File? Six steps and a script of 34 lines
Check a WebP file in six steps. Look at the first bytes, name the kind, use a script and compare two readers. Our 34 line script printed OK for all 194 files and flagged or warned on 17 of 21 damaged copies.
The first looks at a WebP file need no Python. The file command names the layout, webpinfo lists the chunks and xxd shows the first bytes. We used all three on example.
file -b example.webp
RIFF (little-endian) data, Web/P image, VP8 encoding, 64x48, Scaling: [none]x[none], YUV color, decoders should clamp
file -b --mime-type example.webp
image/webp
webpinfo example.webp
File: example.webp
RIFF HEADER:
File size: 238
Chunk VP8 at offset 12, length 226
Width: 64
Height: 48
Alpha: 0
Animation: 0
Format: Lossy (1)
No error detected.
A healthy file starts with RIFF and WEBP and has a chunk that fits. RFC 9649 layouts give the same layout, so a file that breaks these points is damaged, or it is a test file made to break readers.
Check WebP files with Python
The script reads the header and follows the chunks. It checks the sizes, the start code and the picture size. It warns when the RIFF size does not match the file.
It prints OK, WARN or FLAG, and it never changes a file.
import sys, struct
def peek(b):
n = len(b); w = []
if b[:4] != b'RIFF':
i = b.find(b'RIFF')
return 'FLAG', ('%d junk bytes in front of RIFF' % i) if i > 0 else 'no RIFF signature'
if n < 20: return 'FLAG', 'file ends after %d bytes' % n
if b[8:12] != b'WEBP': return 'FLAG', 'bytes 8 to 11 are not WEBP'
rs = struct.unpack('<I', b[4:8])[0]
if rs != n - 8: w.append('RIFF size says %d bytes but the file has %d' % (rs + 8, n))
p, d = 12, ''
while p + 8 <= n and p < rs + 8:
cc = b[p:p+4]; cs = struct.unpack('<I', b[p+4:p+8])[0]
if p == 12 and cc not in (b'VP8 ', b'VP8L', b'VP8X'): return 'FLAG', 'first chunk %r is not VP8, VP8L or VP8X' % cc.decode('latin1')
if p == 12 and cs == 0: return 'FLAG', 'chunk size is 0'
if p + 8 + cs > n: return 'FLAG', 'chunk %s says %d bytes but only %d remain' % (cc.decode('latin1').strip(), cs, n - p - 8)
if cc == b'VP8 ':
if b[p+11:p+14] != b'\x9d\x01\x2a': return 'FLAG', 'VP8 start code is not 9d 01 2a'
if b[p+8] & 1: return 'FLAG', 'first frame is not an intra frame'
W, H = struct.unpack('<HH', b[p+14:p+18]); W &= 0x3fff; H &= 0x3fff
if not W or not H: return 'FLAG', 'size is %d by %d' % (W, H)
d = d or '%d by %d' % (W, H)
elif cc == b'VP8L':
if b[p+8] != 0x2f: return 'FLAG', 'VP8L signature byte is not 2f'
v = struct.unpack('<I', b[p+9:p+13])[0]
d = d or '%d by %d' % ((v & 0x3fff) + 1, ((v >> 14) & 0x3fff) + 1)
elif cc == b'VP8X' and cs >= 10:
d = '%d by %d' % (int.from_bytes(b[p+12:p+15], 'little') + 1, int.from_bytes(b[p+15:p+18], 'little') + 1)
p += 8 + cs + (cs & 1)
if w: return 'WARN', '; '.join(w) + (', ' + d if d else '')
return 'OK', d
if __name__ == '__main__':
for p in sys.argv[1:]:
v, m = peek(open(p, 'rb').read()); print(p, v, m)
Here is what it printed for our example and for four damaged copies.
python3 webp_peek.py example.webp
OK 64 by 48
python3 webp_peek.py A1.webp B6.webp C1.webp C5.webp
A1.webp FLAG no RIFF signature
B6.webp FLAG chunk VP8 says 1000 bytes but only 218 remain
C1.webp OK 64 by 48
C5.webp OK 65 by 48
A healthy answer gives the picture size. A1 has no RIFF tag and gets a flag. B6 says the chunk has 1000 bytes and only 218 remain. C1 and C5 print OK, and both still change the picture. C5 even shows 65 by 48.
What the script found in our files
| Result | Cases |
|---|---|
| Printed OK (194 of 194 files) | The RIFF tag, the sizes, the start code and the picture size fit. 4 of 21 damaged copies also print OK. |
| Printed FLAG (12 of 21 copies) | The script names the first problem it finds, like no RIFF signature or a chunk that is too long. |
| Tags (A1, A2, A5) | The script names a missing RIFF tag, a changed WEBP tag or junk bytes in front. |
| Sizes (A3, A4, A7) | The script warns that the RIFF size does not match the file. All four readers refused A3, and three refused A4 and A7. |
| Chunks (A6, B1, B2, B3, B6, B7) | The script names a chunk that is not VP8, a size above the bytes left, a size of 0 or a file that ends early. |
| Frame data (C3, C4, C7) | The script names a frame that is not an intra frame, a start code that is not 9d 01 2a or a size with a 0 in it. |
| Warned (B4, B5) | Extra bytes at the end. All four readers read both the same as the original. |
| Printed OK but changed (C1, C2, C5, C6) | A flipped bit, zeroed bytes, a new width and swapped bytes. In all four readers the picture was refused or changed. |
The script has limits. It cannot see inside the compressed picture, and it cannot know the right width. It printed OK for 4 copies that still break or change the picture, so OK is not a verdict. The repair routes fix the kinds of damage we tested.
Check order for any WebP file
- Copy your WebP file, write its SHA-256 hash and work on the copy.
-
Look at the first bytes with
xxd -l 32. RIFF then WEBP is a WebP container. See the four kinds. -
Name the kind with
file -band the chunks withwebpinfo. - Use our script. The first word is OK, WARN or FLAG, and a flag names the problem.
- Open the file in two readers and compare the size. The open steps show how.
- Look at the picture. We opened nothing in a browser, so passes show a sound layout for four readers only.
Is a WebP File Safe to Open? Looking is safe, and the decoder needs updates
A WebP file is image data, so looking at one starts nothing. The risk lives in the decoder. libwebp had a serious flaw that was fixed in 1.3.2, so keep your browser and libraries current. We scanned none of our files for malware.
Our readers loaded files and saved pictures in empty folders, and the test files are public. We started no file as a program, we scanned none for malware and we opened none in a browser.
The Debian security tracker lists CVE-2023-4863 as a heap buffer overflow in libwebp before version 1.3.2, and in Chrome before 116.0.5845.187. Our dwebp is 1.3.2. We did not test that flaw, and we have no exploit file. Update your software, and do not rely on the ending.
xxd, file and our script read bytes and start nothing inside the file.
Look at the file before you open it
Check the first bytes and the size. A proper WebP file starts with RIFF and WEBP. If you see something else, check it with file -b and do not open it in an editor until you know what it is.
Our biggest test file is 13,968,454 bytes. RFC 9649 size limits cap a file at under 4 GiB, and Wikipedia limits a side to 16,383 pixels. We did not test huge files, so we give no size limit of our own.
A WebP file from someone else
Read the first bytes and use the script. Open the file in two readers and look at the picture. Work on a copy, and keep your software current.
Share a WebP file with a helper
Send the WebP file and the output of our script and webpinfo. The first word of the script output shows a helper whether the layout is sound. Keep the original, and send a copy.
Not sure? Check it first. Copy the hash, look at the first bytes with our check steps and ask the sender for a fresh file if anything looks wrong. Open it last, on a copy.
Why Will Your WebP File Not Open? Eight causes, and what to do about every one
Most WebP files that will not open fail for one of eight reasons. Look at the first bytes, use the script and try a second reader. Our script flagged or warned on 17 of 21 damaged copies, and our own script restored 11 of the 19 that needed a repair.
We damaged one WebP file in 21 ways and tested a repair script on the copies that needed one. The table groups what we saw into eight causes.
Every row says what happens to your WebP file and what to try next. Fixes work on copies, and none changes the original. We opened no repaired file in a browser, so a repaired file shows only that four Linux readers can read it.
| Cause | Result and fix |
|---|---|
| Wrong first bytes (2) | A1 changes the first R to X, and A5 puts four junk bytes in front. All four readers refused both. Fix: Our script finds RIFF, drops the junk and writes the tag again. Both came back byte for byte. |
| A changed tag or chunk name (2) | A2 changes WEBP to WEBX, and A6 changes VP8 to VP8Z. All four readers refused both. Fix: Our script writes WEBP and the VP8 name again. Both came back byte for byte. |
| A wrong RIFF size (3) | A3 adds 100 and all four readers refused it. A4 takes 100 off and A7 sets 0. Three readers refused both, and ffmpeg read them. Fix: Our script sets the size to the file size minus 8. All three came back byte for byte. |
| A file that is cut short (3) | B1 loses the last byte, B2 the last 100 bytes and B3 all but 12 bytes. All four readers refused all three. Fix: None of ours worked. The missing bytes are gone, so ask for the file again. |
| A wrong chunk size (2) | B6 sets the VP8 size to 1000 and B7 sets it to 0. All four readers refused both. Fix: Our script sets the chunk size from the bytes that follow. Both came back byte for byte. |
| Extra bytes at the end (2) | B4 adds 512 zero bytes and B5 adds a text line. All four readers returned the original image. Fix: None needed for these readers. Our script warns, and it can trim the bytes. |
| A broken frame header (3) | C3 sets the frame type bit and C4 changes the start code. All four readers refused both, and our script restored both. C7 sets the height to 0, and all four refused it. Fix: None for C7. Ask for the file again. |
| Changed picture data (4) | C1 flips a bit, C2 zeroes 64 bytes, C5 sets the width to 65 and C6 swaps two bytes. Readers refused or returned a changed image. Fix: None of ours worked. Ask for the file again. |
When the file is not damaged
Three things look like a damaged WebP file and are not. A reader can lack animation support. A program can be too old for WebP. A file can differ from its ending.
Repairs we tested
A script of 18 lines covers the fixes that need our own code. It takes the damaged WebP file and a name for the new file. It finds RIFF, writes the tags and sizes again and trims bytes after the chunk. For a lossy file it also sets the start code.
import sys, struct
def fix(b):
i = b.find(b'RIFF')
if i < 0 and b[1:4] == b'IFF': i = 0
if i < 0: return b
d = bytearray(b[i:]); d[0:4] = b'RIFF'
if len(d) < 20: return bytes(d)
d[8:12] = b'WEBP'
if d[12:15] == b'VP8' and d[15:16] not in (b' ', b'L', b'X'): d[15:16] = b' '
cs = struct.unpack('<I', d[16:20])[0]
good = 0 < cs and 20 + cs + (cs & 1) <= len(d)
if good: del d[20 + cs + (cs & 1):]
else: struct.pack_into('<I', d, 16, len(d) - 20)
if d[12:16] == b'VP8 ' and len(d) > 30: d[23:26] = b'\x9d\x01\x2a'; d[20] &= 0xfe
struct.pack_into('<I', d, 4, len(d) - 8)
return bytes(d)
if __name__ == '__main__':
open(sys.argv[2], 'wb').write(fix(open(sys.argv[1], 'rb').read()))
# 1 RIFF tag (A1), chunk name (A6), RIFF size (A7), chunk size (B6), start code (C4)
python3 webp_fix.py A1.webp A1_fixed.webp
python3 webp_fix.py A6.webp A6_fixed.webp
python3 webp_fix.py A7.webp A7_fixed.webp
python3 webp_fix.py B6.webp B6_fixed.webp
python3 webp_fix.py C4.webp C4_fixed.webp
# compare with the original
sha256sum example.webp A1_fixed.webp A6_fixed.webp A7_fixed.webp B6_fixed.webp C4_fixed.webp | cut -c1-12
5acee7d76cf3
5acee7d76cf3
5acee7d76cf3
5acee7d76cf3
5acee7d76cf3
5acee7d76cf3
The last lines compare hashes. The first 12 characters match for the original and the five repaired files, so every repaired file equals the original byte for byte. The other 8 copies in the list of 13 came back the same way.
The script handles a simple lossy file with one chunk. We did not test it on lossless, extended or animated files, so do not trust it there.
Fix WebP files that will not open, step by step
We tested the steps on Linux with dwebp 1.3.2, Pillow 12.3.0, ImageMagick 6.9.12 and ffmpeg 6.1.1. We opened no file in a browser, and the steps keep the original untouched at every point.
- Copy your WebP file, write its SHA-256 hash and work on the copy.
-
Name the start with
xxd -l 32and the kinds of WebP file. A WebP file starts with RIFF and WEBP. - Use the check script on this page. A flag or warning names the problem.
- Try a second reader. Pillow and ImageMagick passed all of our files, so use both.
- Match the answer to a cause in the table above and try its fix on the copy.
- If one fix fails, do not stack another on top. Go back to the copy and try the next cause.
- Open the result in two readers, then look at the picture.
What to send a helper
Short messages get faster answers. Include the details below and add the script output. Its first word gives OK, WARN or FLAG.
Subject: My WebP file will not open
File: name, size in bytes and SHA-256 hash
Start: the output of xxd -l 32
Check: the output of webp_peek.py and webpinfo
Program: name, version and the exact words of the error
Source: where the file came from, and how it was sent
What no step can fix
Do not try online repair sites. Sites that offer to fix any picture receive your upload. Try the steps above on a copy first.
How Do You Convert a WebP File to PNG or Make One From a PNG? Four tested routes, and what changed
We converted a 128 by 128 photo of 30,605 bytes to WebP three ways. Lossy at quality 80 gave 3,870 bytes, and lossless gave 21,598 and came back pixel for pixel. We also made, split and read an animated WebP file with libwebp tools.
People convert a WebP file to use it somewhere that wants another format, or they convert a PNG to save space. The commands below do it from a terminal, and every number below is actual. We tested no web converter and no editor.
Convert PNG to WebP
cwebp -q 80 hopper.png -o hopper_q80.webp wrote 3,870 bytes. The PNG is 30,605 bytes, and a JPG at quality 80 was 5,824. Quality 20, 50 and 95 gave 1,666, 2,542 and 7,044 bytes. Lossy means the pixels change.
cwebp -q 80 hopper.png -o hopper_q80.webp
hopper.png 30605 bytes
hopper_q80.webp 3870 bytes
cwebp -q 20 → 1666 cwebp -q 50 → 2542 cwebp -q 95 → 7044
Pillow with quality=80 and ffmpeg with -c:v libwebp -quality 80 also wrote 3,870 bytes. ImageMagick with -quality 80 wrote 3,286. The same number gives other results in other tools, so compare the bytes and the picture.
Against the original photo, the largest pixel difference was 37 and the mean was 3.32 on a scale of 255. That is a loss. Look at both pictures before you delete the PNG.
Convert lossless and back
cwebp -lossless hopper.png -o hopper_ll.webp wrote 21,598 bytes. dwebp hopper_ll.webp -o back.png wrote a PNG of 30,489 bytes. The RGBA pixel hash of the original and the round trip matched, so lossless kept every pixel.
A lossless WebP file was smaller than the PNG here, 21,598 against 30,605 bytes. That is one photo, so do not take it as a rule.
Make and split an animated WebP file
img2webp joined three small PNG frames into one file. anim_dump wrote the frames back as PNG files, and webpmux pulled out one frame as its own WebP file.
img2webp -loop 0 -d 200 -lossless f0.png f1.png f2.png -o anim.webp
output file: anim.webp [3 frames, 206 bytes].
anim_dump anim.webp
Decoding file: anim.webp as ./dump_xxxx.png
webpmux -get frame 2 anim.webp -o fr2.webp
Saved file fr2.webp (42 bytes)
webpmux -info reported 3 frames of 64 by 48 at 200 milliseconds. dwebp and ffmpeg both refused anim.webp, as they did the 16 test files. gif2webp turned a 402 byte GIF into a 206 byte WebP file.
Convert WebP to PNG for an old program
dwebp example.webp -o e.png is the direct route, and it gives a PNG that almost any program opens. It does not undo lossy loss. The PNG stores the pixels that the lossy file already had.
Before you convert
We did not test ICC profiles, EXIF or XMP chunks, so we do not claim that a conversion keeps them. Check the result against the original. Use a new name for the output so the source file stays safe.
webpinfo and our script print the format and write nothing.
Keep the original file. A converted copy can lose pixels, metadata or frames. Keep the original for later edits.
How Does a WebP File Differ From PNG, JPG and GIF Files? One photo, four formats, measured
WebP, PNG, JPG and GIF all store pictures. On one 128 by 128 photo the PNG was 30,605 bytes and the JPG at quality 80 was 5,824. The lossy WebP at quality 80 was 3,870, and the lossless WebP was 21,598. A 3 frame animation took 402 bytes as a GIF and 206 as a WebP file.
The table lists the neighbors of a WebP file and what we measured. We made the files from one photo and one tiny animation. Sizes depend on the tool and the settings, and quality numbers do not match across formats, so they show one case and not a rule.
| Type | What separates it |
|---|---|
| WebP | RIFF container with lossy and lossless modes, alpha and frames. Our photo came to 3,870 bytes lossy and 21,598 lossless. |
| PNG | Lossless. Our photo was 30,605 bytes. Read the PNG page below for the format. |
| JPG | Lossy. Our photo at quality 80 was 5,824 bytes. Read the JPG page below for the format. |
| GIF | Frames with a small color list. Our 3 frame test was 402 bytes as a GIF and 206 as a WebP file. Read the GIF page below for the format. |
WebP or PNG
Both can be lossless. In our test the lossless WebP file was smaller than the PNG, 21,598 against 30,605 bytes. A tiny 64 by 48 gradient gave a PNG of 135 bytes and a lossy WebP file of 238, so test your own pictures.
WebP or JPG
JPG is lossy only. At the same quality number, 80, the WebP file was 3,870 bytes and the JPG 5,824. The numbers mean different things in every tool, so compare the picture and not the setting.
WebP or GIF
A WebP animation can use many colors, and a GIF uses a small list. In our test the WebP file was about half the size of the GIF, 206 against 402 bytes. dwebp and ffmpeg still refused the animation, so check your readers.
Which one do you have
What Is the WebP File Format Made Of? The facts we could check, and where they came from
A WebP file stores a RIFF header and chunks. Facts below come from our own checks of 194 files and 21 damaged copies. Sources are Wikipedia, IANA, RFC 9649 and the four test tools.
| Part | What we could check |
|---|---|
| Maker | Google developed WebP and announced it on 30 September 2010, per Wikipedia. |
| Name | Web picture, with the ending .webp. IANA lists image/webp, and the file command printed the same type for our example. |
| First bytes | RIFF, a 4 byte size and WEBP. Then a chunk named VP8 with a space, VP8L or VP8X. 82, 54 and 58 of our 194 files use those three. |
| Layout | A simple file has one image chunk. An extended file starts with VP8X and can add ICCP, ANIM, ANMF, EXIF and XMP chunks, per RFC 9649. |
| Sizes | The RIFF size is little endian and counts the bytes after the first 8. A chunk size is padded to an even length, per RFC 9649. |
| Compression | Lossy uses VP8 and lossless uses its own method, per Wikipedia. Both can store alpha, and 74 of our files do. |
| Limits | 16,383 pixels on a side, per Wikipedia. An extended canvas stores width and height as 24 bit numbers minus one, per RFC 9649. |
| Animation | Frames live in ANMF chunks with a position, a size, a time, a blend mode and a disposal mode. 16 of our files are animated. |
| Checksum | We found no checksum in the layout. Readers rely on the data, so a flipped bit can pass a header check, as C1 did. |
| Our tests | 194 files, 21 damaged copies, 4 readers, 1 repair route and a script of 34 lines. dwebp 1.3.2, Pillow 12.3.0, ImageMagick 6.9.12 and ffmpeg 6.1.1 on Linux. |
About the values we list
Facts about the layout come from our own reading of one example file and 194 test files, and from the pages we name. RFC 9649 from the IETF is the reference that IANA lists for image/webp.
Where we found no record, we say so. We found no IANA registration date, so we give none. We found no checksum, and we tested no browser.
What we left out
We opened no file in a browser or an editor. We used no web converter and scanned no file for malware. Our readers and scripts worked on Linux, and Windows and macOS programs can accept or refuse files that they treat differently.
All 194 files come from 5 public projects, and many are built to test readers. Our damaged copies come from one small file and change one thing at a time. We did not read the security section of RFC 9649, so we make no claim from it.
Sources checked
For the format, see the Wikipedia article on WebP, the IANA record for image/webp and the full RFC 9649.
For the tools, see the Pillow project and ffmpeg. The test files come from libwebp-test-data, sharp, image-webp, Pillow and libvips. Every count on this page came from files and scripts in our research folder.
Frequently Asked Questions About WebP Files
What is a WebP file?
A WebP file is an image file that Google developed. It stores a lossy or lossless picture, and it can store transparency and a short animation. Google announced the format on 30 September 2010, per Wikipedia.
How do I open a WebP file?
Drag it into a browser window. We also tested dwebp, Pillow, ImageMagick and ffmpeg. Pillow and ImageMagick passed all 194 of our files, and dwebp and ffmpeg passed 178.
Why will my animated WebP file not open?
The reader can lack support for frames. dwebp and ffmpeg refused all 16 animated files in our test, and Pillow and ImageMagick read them. The files were sound, so try another reader.
What is the difference between WebP and PNG?
Both can be lossless, and WebP can also be lossy. On one photo, a lossless WebP file was 21,598 bytes and the PNG was 30,605. A tiny gradient gave a PNG of 135 bytes and a lossy WebP file of 238, so test your own pictures.
Is a WebP file safe to open?
Looking at the bytes starts nothing. The risk lives in the decoder, and libwebp had a serious flaw fixed in version 1.3.2. Keep your browser and libraries current. We scanned none of our files for malware.
How do I convert a WebP file to PNG?
Use dwebp, as in dwebp example.webp -o e.png, or open the file in Pillow and save it. A lossless file came back pixel for pixel in our test. A lossy file keeps the pixels it already had.
How do I convert a PNG to WebP?
Use cwebp. cwebp -q 80 turned our 30,605 byte photo into 3,870 bytes. cwebp -lossless gave 21,598 bytes and kept every pixel. Lossy conversion changes pixels, so keep the original.
How can I check if a WebP file is damaged?
Look at the first bytes, use our script and compare two readers. The script flagged or warned on 17 of 21 damaged copies, and it printed OK for four copies that still broke the picture. Look at the picture too.
Can a damaged WebP file be repaired?
Some damage can be repaired. Our script restored 13 copies byte for byte, and 11 of them needed it. Cut bytes and changed picture data did not come back. Keep the original and work on a copy.
Do all readers agree on a damaged WebP file?
No. dwebp, Pillow, ImageMagick and ffmpeg agreed on 17 of our 21 damaged copies and split on 4. All four returned a changed image on 2 copies. Compare two readers.
How do I split an animated WebP file into frames?
Use anim_dump from libwebp. anim_dump anim.webp wrote our 3 frames as PNG files. webpmux -get frame 2 anim.webp -o fr2.webp pulled out one frame as a 42 byte WebP file.
What MIME type is a WebP file?
IANA lists image/webp with the ending .webp and names RFC 9649 as the reference. The file command printed the same type for our example. We found no registration date, so we give none.
Still Stuck With a WebP File? Where to go next, depending on what went wrong
Look at the first bytes and use the check script. The cause table lists what to try in order.
The kinds table names the kind, and the neighbors name the formats that look alike.
Is it a PNG file? The guide to PNG files covers the lossless image format.
Is it a JPG file? The guide to JPG files covers the lossy photo format.
Is it an animation? The guide to GIF files covers the older animation format.
Is it a file type you do not know? Browse the file extension resource library, or send it on the submit a file type page.
Do you need the format facts? Read the format part for the layout, the limits and the sources of WebP files.