Skip to content

Commit 9158e24

Browse files
committed
Update the readme about new libwebp codec options
1 parent 2021f7d commit 9158e24

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,30 @@ let thumbnailWebpData = SDImageWebPCoder.shared.encodedData(with: image, format:
212212

213213
See more documentation in [SDWebImage Wiki - Coders](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#custom-coder-420)
214214

215+
### Advanced WebP codec options (0.8+)
216+
217+
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:
218+
219+
```objective-c
220+
UIImage *image;
221+
SDImageCoderOptions *options = @{SDImageCoderEncodeWebPMethod: @(0), SDImageCoderEncodeWebPAlphaCompression: @(100)};
222+
NSData *data = [SDImageWebPCoder.sharedCoder encodedDataWithImage:image format:SDImageFormatWebP options:options];
223+
// Will translate into:
224+
// config->method = 0;
225+
// config->alpha_quality = 100;
226+
```
227+
228+
+ Swift
229+
230+
```swift
231+
let image: UIImage
232+
let options = [.encodeWebPMethod: 0, .encodeWebPAlphaCompression: 100]
233+
let data = SDImageWebPCoder.shared.encodedData(with: image, format: .webP, options: options)
234+
// Will translate into:
235+
// config->method = 0;
236+
// config->alpha_quality = 100;
237+
```
238+
215239
## Example
216240

217241
To run the example project, clone the repo, and run `pod install` from the root directory first. Then open `SDWebImageWebPCoder.xcworkspace`.

0 commit comments

Comments
 (0)