2018-08-29 19:50:53 +08:00
# SDWebImageWebPCoder
2018-08-28 23:21:20 +08:00
2018-08-29 19:50:53 +08:00
[![CI Status ](http://img.shields.io/travis/SDWebImage/SDWebImageWebPCoder.svg?style=flat )](https://travis-ci.org/SDWebImage/SDWebImageWebPCoder)
[![Version ](https://img.shields.io/cocoapods/v/SDWebImageWebPCoder.svg?style=flat )](http://cocoapods.org/pods/SDWebImageWebPCoder)
[![License ](https://img.shields.io/cocoapods/l/SDWebImageWebPCoder.svg?style=flat )](http://cocoapods.org/pods/SDWebImageWebPCoder)
[![Platform ](https://img.shields.io/cocoapods/p/SDWebImageWebPCoder.svg?style=flat )](http://cocoapods.org/pods/SDWebImageWebPCoder)
[![Carthage compatible ](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat )](https://github.com/SDWebImage/SDWebImageWebPCoder)
2018-08-28 23:21:20 +08:00
2019-01-28 00:00:34 +08:00
Starting with the SDWebImage 5.0 version, we moved the WebP support code and [libwebp ](https://github.com/webmproject/libwebp ) from the Core Repo to this stand-alone repo.
SDWebImageWebPCoder supports both WebP decoding and encoding, for Static WebP or Animated WebP as well.
2018-08-28 23:21:20 +08:00
## Requirements
+ iOS 8
+ macOS 10.10
+ tvOS 9.0
+ watchOS 2.0
## Installation
#### CocoaPods
2018-08-29 19:50:53 +08:00
SDWebImageWebPCoder is available through [CocoaPods ](http://cocoapods.org ). To install it, simply add the following line to your Podfile:
2018-08-28 23:21:20 +08:00
```ruby
2018-08-29 19:50:53 +08:00
pod 'SDWebImageWebPCoder'
2018-08-28 23:21:20 +08:00
```
#### Carthage
2018-08-29 19:50:53 +08:00
SDWebImageWebPCoder is available through [Carthage ](https://github.com/Carthage/Carthage ).
2018-08-28 23:21:20 +08:00
```
2018-08-29 19:50:53 +08:00
github "SDWebImage/SDWebImageWebPCoder"
2018-08-28 23:21:20 +08:00
```
## Usage
2019-01-28 00:00:34 +08:00
+ Objective-C
2018-08-28 23:21:20 +08:00
```objective-c
2019-01-28 00:00:34 +08:00
// Add coder
2018-08-28 23:21:20 +08:00
SDImageWebPCoder *webPCoder = [SDImageWebPCoder sharedCoder];
2019-01-28 00:00:34 +08:00
[[SDImageCodersManager sharedManager] addCoder:webPCoder];
2018-08-28 23:21:20 +08:00
2019-01-28 00:00:34 +08:00
// WebP image loading
2018-08-28 23:21:20 +08:00
UIImageView *imageView;
2019-01-28 00:00:34 +08:00
NSURL *webpURL;
[imageView sd_setImageWithURL:webpURL];
// WebP image encoding
UIImage *image;
2019-01-28 17:29:41 +08:00
NSData *webpData = [[SDImageWebPCoder sharedCoder] encodedDataWithImage:image format:SDImageFormatWebP options:nil];
2019-01-28 00:00:34 +08:00
```
+ Swift
```swift
// Add coder
let WebPCoder = SDImageWebPCoder.shared
SDImageCodersManager.shared.addCoder(WebPCoder)
// WebP online image loading
let webpURL: URL
let imageView: UIImageView
imageView.sd_setImage(with: webpURL)
// WebP image encoding
let image: UIImage
2019-01-28 17:29:41 +08:00
let webpData = SDImageWebPCoder.shared.encodedData(with: image, format: .webP, options: nil)
2018-08-28 23:21:20 +08:00
```
## Example
To run the example project, clone the repo, and run `pod install` from the Example directory first.
This is a demo to show how to use `WebP` and animated `WebP` images via `SDWebImage` .
2019-01-28 00:00:34 +08:00
## Screenshot
< img src = "https://raw.githubusercontent.com/SDWebImage/SDWebImageWebPCoder/master/Example/Screenshot/WebPDemo.png" width = "300" / >
These WebP images are from [WebP Gallery ](https://developers.google.com/speed/webp/gallery1 ) and [GIF vs APNG vs WebP ](http://littlesvr.ca/apng/gif_apng_webp.html )
2018-08-28 23:21:20 +08:00
## Author
[Bogdan Poplauschi ](https://github.com/bpoplauschi )
2019-01-28 00:00:34 +08:00
[DreamPiggy ](https://github.com/dreampiggy )
2018-08-28 23:21:20 +08:00
## License
2018-08-29 19:50:53 +08:00
SDWebImageWebPCoder is available under the MIT license. See [the LICENSE file ](https://github.com/SDWebImage/SDWebImageWebPCoder/blob/master/LICENSE ) for more info.
2019-01-28 00:00:34 +08:00