Google's latest comprehensive analysis of image formats WEBP

Foreword

Whether it is a PC or a mobile terminal, the picture has been the bulk of traffic to Apple's Retina products represented PPI screen high quality pictures put forward higher requirements, how to ensure narrowed in the fine picture of the picture does not reduce the premise volume , it has become a valuable and worth exploring things.

But now for JPEG, PNG and GIF those optimize image format has almost reached the extreme, if you want to change the status quo to open up a new situation, they have a drastic courage and boldness, while Google gave us a new choice: WebP.

WebP study the origin of the expression in the original mobile phone QQ Mall, due to the expression package larger, slower load in the network environment 2G / 3G's. Beckham colleagues just because the 2013 Google I / O Event learned WebP, so we began the pre-research technique did not impatient with shame, expect to find the most beautiful balance between quality and volume of the original look of the picture.

Google's latest comprehensive analysis of image formats WEBP

This year WebP  image format to get more and more attention, many teams began to preach, while back in the front circle "into Tencent mutual entertainment special front-end technology" is also related topics. Whereby the boom, here to share the process of exploring the previous year as well as new developments this year WebP out together, but also expect more people to apply it to real business.

What is WebP?

WebP (pronunciation weppy), is a lossy compression and lossless compression of image file format, derived from the image encoding format VP8. According to Google's test, WebP lossless compression after less than 45 percent of the file size of the PNG file, even if they PNG files after other compression tools compression, WebP still can reduce file size by 28%.

Released in 2010 WebP longer a novelty, and in Google's star product such as Youtube, Gmail, Google Play can be seen in figure WebP, and even Chrome Web Store has been completely used WebP. Foreign companies such as Facebook, ebay and domestic companies such as Tencent, Taobao, and other US corporations have long been early adopters. At present, many of the project WebP also our factory has been applied, such as Tencent news client, Tencent, QQ space, but also some for WebP image format conversion tools, such as Chi diagram ( http://zhitu.tencent.com ), Isparta ( http://isparta.github.io/ ) and so on.

 

Google's latest comprehensive analysis of image formats WEBP

(Google WebP already being deployed and products)

The good news is, until this year, Google WebP still put on a sustained passion, 2014 Google I / O Event also appeared in two introductory video applications WebP ( https://www.google.com ). WebP has been widely used in the world's most consumed traffic Google products, you have reason to reject it anyway?

Google's latest comprehensive analysis of image formats WEBP

WebP advantage

The above is just a brief introduction to the background and use this image format, but "talk is cheap", where the advantages in this format? In addition to excellent compression effect, the picture quality can be guaranteed? This requires a more rational and objective data:

Here are a simple test: Comparative PNG picture, PNG lossless compression, PNG turn the WebP (lossless), turn the WebP PNG compression (lossy) a. More tests to see   https://isparta.github.io  (please use the Chrome browser to open)

Google's latest comprehensive analysis of image formats WEBP

conclusion can be made:

  • PNG turn WebP compression ratio is higher than the original PNG compression ratio, also supports lossy and lossless compression
  • 转换后的 WebP 体积大幅减少,图片质量也得到保障(同时肉眼几乎无法看出差异)
  • 转换后的 WebP 支持 Alpha 透明和 24-bit 颜色数,不存在 PNG8 色彩不够丰富和在浏览器中可能会出现毛边的问题

WebP 的优势体现在它具有更优的图像数据压缩算法,能带来更小的图片体积,而且拥有肉眼识别无差异的图像质量;同时具备了无损和有损的压缩模式、Alpha 透明以及动画的特性,在 JPEG 和 PNG 上的转化效果都非常优秀、稳定和统一。

科技博客 GigaOM 曾报道:YouTube 的视频略缩图采用 WebP 格式后,网页加载速度提升了 10%;谷歌的 Chrome 网上应用商店采用 WebP 格式图片后,每天可以节省几 TB 的带宽,页面平均加载时间大约减少 1/3;Google+ 移动应用采用 WebP 图片格式后,每天节省了 50TB 数据存储空间。

兼容性与可用性

现在问题来了:WebP 的支持度和兼容性如何?

根据对目前国内浏览器占比与 WebP 的兼容性分析,大约有 50% 以上的国内用户可以直接体验到 WebP,如果你的网站以图片为主,或者你的产品基于 Chromium 内核,建议体验尝试。假如你打算在 App 中使用 WebP,除了 Android4.0 以上提供的原生支持外,其他版本以及 iOS 都可以直接使用官方提供的解析库(Android 、iOS )。

为了验证 WebP 图片格式的业务可行性,我们从流畅度、解码耗时、CPU 使用、内存占用几个维度进行的分析,在开发同学们的帮助下得到了非常宝贵的测试数据:

测试一:

AndroidQQ 下 PNG 和 WebP 各指标对比。

  • 测试环境:AndroidQQ、Galaxy Nexus、Android4.2.2 系统
  • 测试对象:WebP、PNG

测试数据(部分):

Google's latest comprehensive analysis of image formats WEBP

测试结论:

  • 解码耗时:WebP 的解码时间是 PNG 格式的 4.4 倍(24.8ms)
  • 流畅程度:两种格式下,AIO 滑动流畅度无明显差异
  • CPU使用:两种格式下,连续发送 15 个表情,CPU 使用均在 10%—26% 之间波动,两者无明显差异
  • 内存占用:两者格式下,连续发送 15 个表情,PSS 内存占用跨度均为 11M,无明显差异

测试二:

iPhoneQQ 下 PNG 和 WebP 各指标对比。

  • 测试环境:iPhoneQQ、iPhone4、iOS5.1.1 系统
  • 测试对象:WebP、PNG

测试数据(部分):

Google's latest comprehensive analysis of image formats WEBP

测试结论:

  • 解码耗时:WebP 的解码时间是 PNG 的 5 倍 左右(64.1ms)
  • 流畅程度:WebP 的 FPS 平均值会比 PNG 的平均值要小,但是比较稳定,跨度不大,性能也相差不大
  • CPU使用:总体上看,PNG 格式的表情使用 CPU 波动比较大。从平均值来看 WebP 格式表情占用的 CPU 会比 PNG 表情的占用率大
  • 内存占用:WebP 格式表情,占用内存的跨度为 4M,波动比较明显。PNG 格式表情,占用内存的跨度为 5M,没有明显波动。停止发送表情后,40s 左右内存均有回降

可见除了 WebP 在解码时间与 PNG 有较明显差异(毫秒级别)之外,总体使用体验和 PNG 基本无差异。同时也需要明确,移动设备的发展迅猛,硬件升级快,上一年的表现也许在今年又有了明显的提升。所以,在 App 中使用 WebP 基本没有技术阻碍。

对原创表情商城的技术指导

在验证了业务可行性之后,WebP 又激发了我们对另外一些方向的思考:既然它表现如此优秀,能否进一步摸清其“秉性”,得到一些能在未来使用中遵循的指导方案?

于是,为了更深入了解 WebP 特性,我们针对原创表情项目 “不同的表情图片,如何获得 WebP 的最佳压缩效率” 问题继续展开探究,主要从图片规格、色彩数(颜色数量)、参数配置几个维度进行:

探索一:图片规格

通过阅读文献了解到 WebP 使用的是 Fancy 采样算法,既然是采样算法必然有采样区块,而 JPEG 的采样区块是 8*8,对于原始图片的长宽不是 8 的倍数,都需要先补成 8 的倍数,使其能一块块的处理,所以对于 8 的整数倍的图片,压缩会更高效。

那么 WebP 的采样区块会是多少?我们在其他因素保持不变的前提下改变图片规格,选取了 200*200 附近多个规格值,得到了一些数据。将数据可视化之后可以看到凡是以 16*16 倍数(160*160、176*176、192*192、256*256)为规格的图片,有损压缩的比例都明显大于以 4*4 或 8*8 的倍数为规格的图片。

Google's latest comprehensive analysis of image formats WEBP

结论:

原创表情可以考虑使用 “16n*16n” 的规格。目前原创表情选择的是 200*200 的规格大小,实际上选择 256*256 或者 192*192 能获得更高的 WebP 压缩效率,量级在千分之几。

探索二:色彩数

在 JPEG 和 PNG 格式的选择经验上可以知道,对于色彩复杂的图片,一般使用 JPEG 格式,而对于色彩单一的图片,使用 PNG 格式。可见色彩数会影响图片的压缩效果。于是我们通过 Photoshop 中的色阶分离功能调整表情图片的色彩数,在其他因素保持不变的前提下对比不同色彩数对于 WebP 有损无损压缩的影响。

Google's latest comprehensive analysis of image formats WEBP

可见,在色彩数相对较少的前提下,无损压缩的效果要优于有损压缩;而色彩数很多时,有损压缩效果要优于无损压缩,这个分界点在 256±100 之间。

结论:

建议原创表情尽量控制颜色数在 256 色以内,采用无损压缩性价比最高。

  • 小于 256 色:以图标,图形,剪贴画为代表,最适合采用 WebP 无损压缩,精细度完美,体积大幅减少;
  • 大于 256 色:以多数表情图,广告图为代表,最适合采用 WebP 有损压缩,选择较高压缩比(建议压缩质量为 100% ~ 75%)
  • 远大于 256 色:以风景照,视频截图为代表,最适合采用 WebP 有损压缩,选择适中压缩比(建议压缩质量为 75% 以下)

探索三:色温、渐变与杂色、直线与直线、描边

Google's latest comprehensive analysis of image formats WEBP

随后又从色温、渐变与杂色、直线曲线、是否需要描边上进行了分析,最后的结论即:

  • 色温并不会影响表情图片的压缩效果,可大胆用色
  • 渐变与杂色理论上都是增加色彩数,它的压缩规律从符合第二条,但建议表情图片少用渐变杂色和不必要的线条
  • 直线与曲线理论上也是增加了色彩数(因为曲线边缘会存在渐变),建议如果表情中可以“直”的地方就不要“弯”
  • WebP 格式的图片不会存在毛边问题,所以不需要为表情图片添加描边

探索四:压缩配置

为了得到无损压缩和有损压缩的最佳压缩配置,我们通过对 900 张表情图片进行不同压缩配置的测试(大部分表情图片的色彩数都在 256 色以上),得到下面的数据:

Google's latest comprehensive analysis of image formats WEBP

压缩参数说明:

  • -lossless:无损压缩
  • -q:压缩质量,值越大越图片质量越好
  • -m:压缩方式,值越大则图片质量越好,体积越小,但是耗时较长

可以发现,无损压缩表现很稳定,压缩质量越高,压缩效果也越好。而有损压缩在压缩质量设置为 75 以上之后,压缩效果反而减弱,甚至压缩后的图片体积会大于压缩前的体积。所以得出以下结论:

  • 选择无损压缩时,“-lossless -q 100” 是最佳方案
  • 选择有损压缩时,“-q 75”是最佳方案(图片质量与体积大小达到均衡)
  • 无论何种压缩参数,加上“-m 6”都能使得输出的 WebP 图片进一步减少体积,量级是1%~2%,但是会增加耗时

最终,得出了一个正反面案例,从技术角度分析不同的表情图标的优劣(强调一下是“技术角度”,这里列举的表情都很赞 ^_^)。

Google's latest comprehensive analysis of image formats WEBP

动态 WebP 初探

了解完静态 WebP,下面再了解一下动态 WebP(Animated WebP):2013 年 11 月 21 日,Animated WebP 终于取得进展,并在 Chrome32 Beta 中得到了支持。目前 Animated WebP 支持将 GIF 直接转换成 Animated WebP,或者将多张 WebP 图片组合成 Animated WebP。与传统的 GIF 图比较,Animated WebP 的优势在于:

  • 支持有损和无损压缩,并且可以合并有损和无损图片帧
  • 体积更小,GIF 转成有损 Animated WebP 后可以减小 64% 的体积,转成无损可以节省 19% 的体积
  • 颜色更丰富,支持 24-bit 的 RGB 颜色以及 8-bit 的 Alpha 透明通道(而 GIF 只支持 8-bit RGB 颜色以及 1-bit 的透明)
  • 添加了关键帧、metadata 等数据

假如你在使用 Chrome32 以上的浏览器,可以点这里(https://isparta.github.io)体验。

Google's latest comprehensive analysis of image formats WEBP

但新兴的事物必然存在不足的地方,Animated WebP 存在的问题:

  • 消耗较多的 CPU 和解码时间(多 1.5~2.2 倍)
  • 和 GIF 相比起来支持度还不够,目前仍无法通用
  • 为了支持 Animated WebP,Chrome 的新内核 Blink 添加了近 1500 行的代码

根据自己实际的测试,发现 Animated WebP 的压缩效果较不稳定,在默认压缩配置下达不到 Google 官方提供的示例效果。但 Animated WebP 依然有很多值得期待的空间,值得继续关注。

综合技术方案

对于不同场景下 WebP 的使用,我们总结了一些解决方案,如下:
1、若使用场景是浏览器,可以:

  • JavaScript 能力检测,对支持 WebP 的用户输出 WebP 图片
  • WebP support the use of plug-ins: WebPJS: http://webpjs.appspot.com

2, the use of scenarios is App, you can:

3, conversion tools:

iSparta our group for the transformation and APNG two new WebP image format developed a desktop application, direct batch convert images to WebP, while providing a variety of parameters, welcome experience.

Google's latest comprehensive analysis of image formats WEBP

Article from CSDN lava

Original link: https://blog.csdn.net/zhangcanyan/article/details/51842211

Guess you like

Origin www.cnblogs.com/SallyShan/p/11461916.html