docs/_docs/webp-support.md
WebP is an image format that supports lossy and lossless compressions. Furthermore, it allows for transparency and animations.
Android added WebP support in version 4.0 and improved it in 4.2.1:
By adding the Fresco webpsupport module, apps can display all kinds of WebP images on all versions of Android:
| Configuration | Basic WebP | Lossless or Transparent WebP | Animated WebP |
|---|---|---|---|
| OS < 4.0 | |||
| OS >= 4.0 | ✓ | ||
| OS >= 4.2.1 | ✓ | ✓ | |
| Any OS + webpsupport | ✓ | ✓ | |
| Any OS + animated-webp | ✓ | (✓ if webpsupport or OS >= 4.2.1) | ✓ |
The only thing you need to do is add the webpsupport library to your dependencies. This adds support for all types of non-animated WebP images. E.g. you can use it to display transparent WebP images on Gingerbread.
dependencies {
// ... your app's other dependencies
implementation 'com.facebook.fresco:webpsupport:{{site.current_version}}'
}
In order to display animated WebP images, you have to add the following dependencies:
dependencies {
// ... your app's other dependencies
implementation 'com.facebook.fresco:animated-webp:{{site.current_version}}'
implementation 'com.facebook.fresco:webpsupport:{{site.current_version}}'
}
You can then load the animated WebP images like any other URI. In order to auto-start the animation, you can set setAutoPlayAnimations(true) on the DraweeController:
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setUri("http://example.org/somefolder/animated.webp")
.setAutoPlayAnimations(true)
.build();
mSimpleDraweeView.setController(controller);
For the full sample see the ImageFormatWebpFragment in the showcase app: ImageFormatWebpFragment.java