From 9158e2429fe18df079b67b71957704ad025b25c5 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 14 Dec 2020 15:01:11 +0800 Subject: [PATCH] Update the readme about new libwebp codec options --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index de2a781..31b8441 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,30 @@ let thumbnailWebpData = SDImageWebPCoder.shared.encodedData(with: image, format: See more documentation in [SDWebImage Wiki - Coders](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#custom-coder-420) +### Advanced WebP codec options (0.8+) + +The WebP codec [libwebp](https://developers.google.com/speed/webp/docs/api) we use, supports some advanced control options for encoding/decoding. You can pass them to libwebp by using the wrapper top level API: + +```objective-c +UIImage *image; +SDImageCoderOptions *options = @{SDImageCoderEncodeWebPMethod: @(0), SDImageCoderEncodeWebPAlphaCompression: @(100)}; +NSData *data = [SDImageWebPCoder.sharedCoder encodedDataWithImage:image format:SDImageFormatWebP options:options]; +// Will translate into: +// config->method = 0; +// config->alpha_quality = 100; +``` + ++ Swift + +```swift +let image: UIImage +let options = [.encodeWebPMethod: 0, .encodeWebPAlphaCompression: 100] +let data = SDImageWebPCoder.shared.encodedData(with: image, format: .webP, options: options) +// Will translate into: +// config->method = 0; +// config->alpha_quality = 100; +``` + ## Example To run the example project, clone the repo, and run `pod install` from the root directory first. Then open `SDWebImageWebPCoder.xcworkspace`.