WMS WebP输出格式

此模块添加了 WebP WMS输出格式。

WMS GetMap请求: FORMAT=image/webp

与其他格式相比,WebP图像格式的优势:

  • WebP有损图像比可比的JPEG图像小约30%。
  • WebP支持透明度,通常提供的文件大小比PNG小3倍。
  • WebP支持 paletted images ,通常提供比PNG小20%的文件大小。

Attention! Unfortunately, all the advantages of the WebP format regarding file size are negated by a more complex, time and energy-consuming processing.

However, the WebP format could serve as an input format for the GWC and then play out the advantages again. Work is in progress.

Read more about it here: WebP processing

只有在互联网连接速度较慢的特殊情况下(例如G3),此格式才有意义。

所有现代浏览器都支持WebP (caniuse )。但是,可以在客户端构建向后兼容性。使用 Google's recommended function 使用Java脚本检测浏览器是否支持WebP。请注意,使用的图像加载是非阻塞和异步的。任何依赖的代码都应该放在回调函数中。

示例 OpenLayers v7 通过Java脚本检查WebP浏览器支持情况:

...
import ImageLayer from 'ol/layer/Image';
import ImageWMS from 'ol/source/ImageWMS';
...
function check_webp_feature(feature, callback) {
... // code from google link above
}
check_webp_feature('lossless', function (feature, isSupported) {
  let wmsoutputformat = 'image/webp'
  if (!isSupported) {
         wmsoutputformat = 'image/png'
  }
  var wmsLayerSource = new ImageWMS({
    params: {'LAYERS': 'yourLayerName','FORMAT': wmsoutputformat},
    ...
  });
  ... // your OL code
});

由于使用了本机库,因此并非所有平台都受支持。不过,对于那些受支持的系统,不需要安装额外的本地库。该插件基于 Java ImageIO WebP support ,您可以在这里找到更多信息。如果您的平台不受支持,则有 instructions for compiling the native library 。在这种情况下,不要忘记做出贡献。