# WebP

**WebP** 是一种基于资源交换文件格式（RIFF）的图像文件格式，支持有损与无损压缩、Alpha 透明和动画。谷歌于 2010 年 9 月以开发者预览版的形式发布该格式，旨在缩减网络上照片的字节体积，如今它已由 IETF 标准化为 RFC 9649。<sup>[1](https://datatracker.ietf.org/doc/html/rfc9649)</sup><sup> • </sup><sup>[2](https://developers.googleblog.com/webp-a-new-image-format-for-the-web/)</sup>

| 关键事实 | 详情 |
|---|---|
| 标准化 | 基于 RIFF 的容器，标准化为 RFC 9649；支持有损、无损、Alpha 和动画<sup>[1](https://datatracker.ietf.org/doc/html/rfc9649)</sup> |
| 有损基础 | VP8 帧内编码（RFC 6386），配合块自适应量化和布尔算术熵编码<sup>[1](https://datatracker.ietf.org/doc/html/rfc9649)</sup><sup> • </sup><sup>[3](https://developers.google.com/speed/webp/docs/compression)</sup> |
| 谷歌的节省声明 | 在等效 SSIM 下比 JPEG 小 25%–34%，通过有损加 Alpha 编码比 PNG 小 60%–70%<sup>[4](https://developers.google.com/speed/webp/docs/webp_study)</sup><sup> • </sup><sup>[3](https://developers.google.com/speed/webp/docs/compression)</sup> |
| 独立基准测试 | 在 SSIM 0.95 下比优化后的 JPEG 小约 22%，而 AVIF 为 37%，JPEG XL 为 18%<sup>[5](https://cleanor.app/papers/next-gen-image-formats-2026.pdf)</sup> |
| 限制 | 8 位 sRGB 色彩，不支持 HDR，最大尺寸 16,383 × 16,383 像素<sup>[6](https://pixotter.com/blog/jpeg-xl-vs-avif-vs-webp/)</sup> |
| 采用率 | 22.5% 的网站使用（W3Techs），约占图像请求的 17%；Web Almanac 统计占所有已提供图像的 12%<sup>[7](https://w3techs.com/technologies/comparison/im-avif,im-jpeg,im-webp)</sup><sup> • </sup><sup>[8](https://www.pagespeedmatters.com/resources/data-studies/image-formats-of-the-web)</sup><sup> • </sup><sup>[9](https://file-convert-factory.org/en/blog/web-image-formats-guide)</sup> |
| 安全 | CVE-2023-4863，libwebp 无损解码器中的堆缓冲区溢出漏洞，已被在野利用，在 libwebp 1.3.2 中修复<sup>[10](https://safeguard.sh/resources/blog/webp-libwebp-cve-2023-4863-deep-dive)</sup><sup> • </sup><sup>[11](https://safeguard.sh/resources/blog/libwebp-vulnerability)</sup> |

## 起源与动机

谷歌的工程师于 2010 年开始着手研究，能否对 JPEG 这类有损图像进行进一步压缩，使页面加载更快，同时保持质量和分辨率不变。他们产出的格式将 VP8 视频编解码器的帧内编码技术应用于静态图像——VP8 的技术是谷歌从 On2 Technologies 收购、并于 2010 年 5 月开源的。其容器是一种轻量级 RIFF 结构，每张图像仅增加 20 字节的开销。<sup>[2](https://developers.googleblog.com/webp-a-new-image-format-for-the-web/)</sup>

为了评估机会的大小，谷歌从网络上随机抽取了约 1,000,000 张图像，其中大部分为 JPEG，也有一些 PNG 和 GIF，在不产生可感知视觉质量损失的前提下将它们重新编码为 WebP。结果文件大小平均缩减了 39%。<sup>[2](https://developers.googleblog.com/webp-a-new-image-format-for-the-web/)</sup>

## 技术设计

**有损流水线。** 有损 WebP 基于 VP8 关键帧编码构建。VP8 由 On2 Technologies 开发，是 VP6 和 VP7 的后继者，它在宏块上使用基于块的预测编码：利用已解码的相邻块形成每个块的预测值，从实际像素中减去该预测值，残差经离散余弦变换、量化（唯一的有损步骤）后进行熵编码。<sup>[3](https://developers.google.com/speed/webp/docs/compression)</sup> 相比之下，JPEG 直接对固定的 8 × 8 像素块应用离散余弦变换 并量化频率系数。<sup>[12](https://link.springer.com/article/10.1007/s11760-025-04579-6)</sup> 谷歌将 WebP 相对于 JPEG 的优势主要归因于预测编码，块自适应量化——根据分段熵分配比特——构成了很大的次要差异，而布尔算术熵编码相较于 JPEG 使用的[霍夫曼编码](https://www.edgepedia.org/zh/huffman-coding)，又将压缩效率提高了 5%–10%。<sup>[3](https://developers.google.com/speed/webp/docs/compression)</sup>

**无损流水线。** 无损算法精确存储和还原像素值，包括完全透明像素的颜色值。它依次应用空间预测、色彩空间变换、局部生成的调色板、像素打包和 Alpha 替换，然后使用 LZ77 的变体，配合前缀（霍夫曼）编码、二维距离编码和用于近期使用颜色的颜色缓存。<sup>[1](https://datatracker.ietf.org/doc/html/rfc9649)</sup><sup> • </sup><sup>[3](https://developers.google.com/speed/webp/docs/compression)</sup>

**Alpha 与动画。** WebP 还提供了一种它所替代的格式不具备的模式：有损 RGB 与无损 Alpha 的组合。对 Alpha 通道进行无损编码比有损质量 90 的编码增加约 22% 的字节，而用有损加 Alpha 的 WebP 替代透明 PNG 平均可节省 60%–70% 的文件大小。<sup>[3](https://developers.google.com/speed/webp/docs/compression)</sup>

## 压缩性能

谷歌自己的压缩研究在 Lenna、Kodak、Tecnik 和 Image_crawl 图像集上以等效 SSIM 指数比较了 WebP 和 JPEG，发现 WebP 文件大小平均比 JPEG 小 25%–34%。具体示例包括：Lenna 为 17.4 KB（SSIM 0.841），JPEG 为 23.5 KB（0.840），比率为 0.74；一张 Image_crawl 图像为 6.5 KB（0.901），JPEG 为 9.9 KB（0.899），比率为 0.66；SSIM 对每像素比特数的图表显示，WebP 在相同 SSIM 下始终需要更少的每像素比特数。<sup>[4](https://developers.google.com/speed/webp/docs/webp_study)</sup>

独立测量则对这些数字有所修正。一项同行评审的评估发现，WebP 在自然图像、比特率不超过约 1 bpp 时表现高效，在峰值信噪比和基于人类视觉系统的指标上往往略优于竞争编解码器，但指出在高分辨率、高度细节化或合成图像上以及超过约 1 bpp 时性能下降，并出现一种归因于环路滤波的模糊效应。<sup>[13](https://eudl.eu/pdf/10.1007/978-3-642-30419-4_22)</sup> 一项在 SSIM 0.95 下的匹配质量基准测试显示，WebP 比优化后的 JPEG 小约 22%，落后于 AVIF 的约 37%，领先于 [JPEG XL](https://www.edgepedia.org/zh/jpeg-xl) 的约 18%。<sup>[5](https://cleanor.app/papers/next-gen-image-formats-2026.pdf)</sup> 在接近无损的质量（SSIM 0.98）下，一项五张照片的基准测试发现 WebP 和 JPEG 几乎相同，WebP 比 JPEG 大 3%。<sup>[14](https://www.sammapix.com/blog/avif-vs-webp-vs-jpeg-benchmark-2026)</sup> 谷歌的研究和 SSIM 0.95 基准测试发现在测试设置下 WebP 比 JPEG 小；而所引用的接近无损基准测试则发现 WebP 大 3%。

## 与 AVIF 和 JPEG XL 的比较

在每字节质量方面，AVIF 领先：一项比较显示 AVIF 输出通常比 JPEG 小 40%–50%，比 WebP 小 20%–30%，上述匹配质量基准测试给出 AVIF 相对优化 JPEG 节省 37%，而 WebP 为 22%。<sup>[15](https://fileformer.com/en/articles/guides/best-file-formats-for-web-webp-avif-jpg-compared)</sup><sup> • </sup><sup>[5](https://cleanor.app/papers/next-gen-image-formats-2026.pdf)</sup> 在速度方面，排序则相反。在一项针对 4000 × 3000 照片的基准测试中，WebP 质量 78（libwebp 方法 6）生成的文件大小为 1.02 MB，编码耗时 0.94 秒，解码耗时 0.11 秒，而 AVIF 质量 58（libavif 速度 4）产生更小的 0.67 MB 文件，但编码需要 6.42 秒；JPEG q82 以 1.60 MB 在 0.31 秒内完成编码。<sup>[15](https://fileformer.com/en/articles/guides/best-file-formats-for-web-webp-avif-jpg-compared)</sup> 相对于 mozjpeg 基线，WebP 文件大小为基线的 72%–78%，编码时间为 3–5 倍，解码时间为 1.2 倍；而 AVIF 在 libaom 速度 4 下为基线的 50%–60%，编码时间为 50–100 倍。<sup>[16](https://lpic.cc/en/blog/webp-avif-jpegxl-format-comparison)</sup> 视设置不同，WebP 的编码速度大约比 JPEG XL 快 10–50 倍。<sup>[6](https://pixotter.com/blog/jpeg-xl-vs-avif-vs-webp/)</sup>

功能差距也很重要。WebP 使用 8 位色彩，支持 8 位 Alpha 和动画，上限为 16,383 × 16,383 像素，而 AVIF 可达 65,535 × 65,535 并支持最高 12 位色彩；WebP 不支持 HDR 和渐进式加载。<sup>[6](https://pixotter.com/blog/jpeg-xl-vs-avif-vs-webp/)</sup><sup> • </sup><sup>[16](https://lpic.cc/en/blog/webp-avif-jpegxl-format-comparison)</sup> JPEG XL 的独特能力是对现有 JPEG 进行无损重压缩，这是包括 WebP 在内的其他格式都不提供的，尽管各方对节省幅度说法不一：一项基准测试报告约 8% 且可精确还原，<sup>[5](https://cleanor.app/papers/next-gen-image-formats-2026.pdf)</sup> 另一项则报告约 20%。<sup>[16](https://lpic.cc/en/blog/webp-avif-jpegxl-format-comparison)</sup> 在浏览器覆盖方面，WebP 覆盖约 96%–97% 的用户，AVIF 约 93%，而 JPEG XL 仅约 14%–25%（Safari，加上部分 Firefox）；Chrome 于 2023 年移除 JPEG XL，截至 2026 年仅通过标志位提供。<sup>[5](https://cleanor.app/papers/next-gen-image-formats-2026.pdf)</sup><sup> • </sup><sup>[6](https://pixotter.com/blog/jpeg-xl-vs-avif-vs-webp/)</sup> 因此一个普遍推荐的交付栈是 AVIF 优先、WebP 回退、JPEG 兜底。<sup>[5](https://cleanor.app/papers/next-gen-image-formats-2026.pdf)</sup>

## 采用与生态系统支持

浏览器支持分阶段到来：Chrome 32 于 2014 年 1 月，Edge 18 于 2018 年 11 月，Firefox 65 于 2019 年 1 月，Safari 14 于 2020 年 9 月，此后所有主流浏览器均原生支持 WebP。<sup>[9](https://file-convert-factory.org/en/blog/web-image-formats-guide)</sup><sup> • </sup><sup>[15](https://fileformer.com/en/articles/guides/best-file-formats-for-web-webp-avif-jpg-compared)</sup> libwebp 参考实现提供了 cwebp 和 dwebp 命令行工具，[ImageMagick](https://www.edgepedia.org/zh/imagemagick)、sharp、libvips、GIMP、Photoshop 和 [Affinity Photo](https://www.edgepedia.org/zh/affinity-photo) 均支持该格式。<sup>[15](https://fileformer.com/en/articles/guides/best-file-formats-for-web-webp-avif-jpg-compared)</sup>

使用率的统计因分母而异。W3Techs 统计 WebP 占所有网站的 22.5%，JPEG 为 69.3%，AVIF 为 1.7%。<sup>[7](https://w3techs.com/technologies/comparison/im-avif,im-jpeg,im-webp)</sup> 图像请求统计将 WebP 排在 JPEG 和 PNG 之后，约占所有图像请求的 17%，40% 的首页至少提供一张 WebP 图像。<sup>[8](https://www.pagespeedmatters.com/resources/data-studies/image-formats-of-the-web)</sup> HTTP Archive 的 Web Almanac 2024 发现 WebP 占所有已提供图像的 12%，比 2022 年上升三个百分点，而 JPEG 从 40% 降至 32%。<sup>[9](https://file-convert-factory.org/en/blog/web-image-formats-guide)</sup> 对于主导页面加载性能的图像，2025 年 Web Almanac 测得[最大内容绘制](https://www.edgepedia.org/zh/largest-contentful-paint)图像的格式为 JPEG 57%、PNG 26%、WebP 11%、AVIF 0.7%。<sup>[17](https://focaltool.com/blog/webp-vs-avif-vs-jpeg)</sup>

## 实践中的部署

标准的回退模式是 HTML picture 元素：一个 type 为 image/webp 的 source，后跟一个 JPEG 回退。浏览器使用它支持的第一个列出的 source，否则回退到 img 标签，因此旧版浏览器无需客户端脚本即可收到 JPEG。<sup>[18](https://web.dev/articles/serve-images-webp)</sup> 实际摩擦包括：变体变更时的 CDN 缓存失效、集中在旧款安卓手机和企业设备群中的残余不支持用户，以及编码器比 libjpeg 消耗更多 CPU——这对即时转换很重要。<sup>[9](https://file-convert-factory.org/en/blog/web-image-formats-guide)</sup>

编码成本随模式急剧变化。在一个 46 张图像的语料库上，无损 WebP 编码总共耗时 200 秒，而质量 80 为 24 秒；手机照片的无损 WebP 产生的文件是质量 80 大小的 10.2 倍（43.7 MB 对 4.3 MB），平面图形为 2.1 倍，透明图像为 1.4 倍——在后者中无损才真正划算。<sup>[19](https://swiftconverter.io/blog/image-format-benchmark)</sup> 早期的独立评估同样发现该实现在编码方面相当低效，但在解码低分辨率图像方面速度尚可。<sup>[13](https://eudl.eu/pdf/10.1007/978-3-642-30419-4_22)</sup>

## 安全与 2023 年 libwebp 漏洞

CVE-2023-4863 是 libwebp 在处理无损 WebP 时的一个堆缓冲区溢出漏洞，具体位于解码期间使用的霍夫曼编码逻辑中（vp8l 解码代码中的 BuildHuffmanTable 路径）。攻击者只需诱使受害者访问一个设有陷阱的网页即可触发，可能在图像解码期间破坏内存。NVD 在 CVSS v3.1 上评分为 8.8（AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H），可网络利用，对机密性、完整性和可用性影响均为高。<sup>[10](https://safeguard.sh/resources/blog/webp-libwebp-cve-2023-4863-deep-dive)</sup> 该漏洞已被在野利用，在 libwebp 1.3.2 及更高版本中修复；由于 libwebp 嵌入在浏览器和 Electron 应用中，暴露范围远远超出了图像处理服务器。<sup>[11](https://safeguard.sh/resources/blog/libwebp-vulnerability)</sup>

这一风险是结构性的而非偶发的。RFC 9649 记录了实现该格式的安全考量，包括整数溢出、对堆和栈的越界读写、未初始化数据使用、空指针解引用和资源耗尽，并指出解码器常常在浏览器、电子邮件客户端和接受上传的服务器中处理不受信任的输入。<sup>[1](https://datatracker.ietf.org/doc/html/rfc9649)</sup>

## References

1. [RFC 9649: WebP Image Format, IETF](https://datatracker.ietf.org/doc/html/rfc9649)
2. [WebP, a new image format for the Web, Google Developers Blog (2010)](https://developers.googleblog.com/webp-a-new-image-format-for-the-web/)
3. [Compression Techniques, WebP documentation, Google for Developers](https://developers.google.com/speed/webp/docs/compression)
4. [WebP Compression Study, Google for Developers](https://developers.google.com/speed/webp/docs/webp_study)
5. [State of Next-Gen Image Formats 2026: A Matched-Quality Benchmark](https://cleanor.app/papers/next-gen-image-formats-2026.pdf)
6. [JPEG XL vs AVIF vs WebP: Which Format Wins in 2026?, Pixotter](https://pixotter.com/blog/jpeg-xl-vs-avif-vs-webp/)
7. [JPEG vs. WebP vs. AVIF usage statistics, W3Techs](https://w3techs.com/technologies/comparison/im-avif,im-jpeg,im-webp)
8. [Image Format Statistics: WebP at ~17% of Images, PageSpeed Matters](https://www.pagespeedmatters.com/resources/data-studies/image-formats-of-the-web)
9. [Choosing Web Image Formats in 2026, File Convert Factory](https://file-convert-factory.org/en/blog/web-image-formats-guide)
10. [CVE-2023-4863: The libwebp Heap Overflow Explained, Safeguard](https://safeguard.sh/resources/blog/webp-libwebp-cve-2023-4863-deep-dive)
11. [libwebp Vulnerability CVE-2023-4863: Fix Guide, Safeguard](https://safeguard.sh/resources/blog/libwebp-vulnerability)
12. [Comparative survey of image compression methods, Signal, Image and Video Processing (2025)](https://link.springer.com/article/10.1007/s11760-025-04579-6)
13. [Objective Evaluation of WebP Image Compression Efficiency, LNICST 79](https://eudl.eu/pdf/10.1007/978-3-642-30419-4_22)
14. [AVIF vs WebP vs JPEG: Real Benchmark (2026), SammaPix](https://www.sammapix.com/blog/avif-vs-webp-vs-jpeg-benchmark-2026)
15. [Best File Formats for the Web: WebP, AVIF, and JPG Compared, FileFormer](https://fileformer.com/en/articles/guides/best-file-formats-for-web-webp-avif-jpg-compared)
16. [WebP vs AVIF vs JPEG XL 2026: Complete Format Comparison, LPIC](https://lpic.cc/en/blog/webp-avif-jpegxl-format-comparison)
17. [WebP vs AVIF vs JPEG, Focal](https://focaltool.com/blog/webp-vs-avif-vs-jpeg)
18. [Serve images in WebP formats, web.dev](https://web.dev/articles/serve-images-webp)
19. [Image format benchmark: PNG vs JPG vs WebP vs AVIF, SwiftConverter](https://swiftconverter.io/blog/image-format-benchmark)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Oct 15, 2026 · Edited: Oct 15, 2026; Oct 25, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Data formats and serialization › Image and video formats

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/webp

English original: https://www.edgepedia.org/webp
