Skip to content

Commit 97ff5b0

Browse files
committed
Update the README and example to the latest version, show SDAnimatedImageView usage
1 parent 22d83f7 commit 97ff5b0

File tree

4 files changed

+76
-22
lines changed

4 files changed

+76
-22
lines changed

Example/SDWebImageWebPCoderExample/Base.lproj/Main.storyboard

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
66
<dependencies>
77
<deployment identifier="iOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
99
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
1010
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1111
</dependencies>
@@ -17,23 +17,9 @@
1717
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
1818
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1919
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
20-
<subviews>
21-
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="RFu-Oe-4ia">
22-
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
23-
</imageView>
24-
</subviews>
2520
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
26-
<constraints>
27-
<constraint firstItem="RFu-Oe-4ia" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="Sdh-Zp-74C"/>
28-
<constraint firstItem="RFu-Oe-4ia" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="U5c-8s-Ehx"/>
29-
<constraint firstItem="RFu-Oe-4ia" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="eH6-kl-Kl9"/>
30-
<constraint firstItem="RFu-Oe-4ia" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" id="l7U-la-kh4"/>
31-
</constraints>
3221
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
3322
</view>
34-
<connections>
35-
<outlet property="imageView" destination="RFu-Oe-4ia" id="IV9-xD-bYt"/>
36-
</connections>
3723
</viewController>
3824
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
3925
</objects>

Example/SDWebImageWebPCoderExample/ViewController.m

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
#import <SDWebImage/SDWebImage.h>
1212

1313
@interface ViewController ()
14-
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
14+
@property (nonatomic, strong) UIImageView *imageView1;
15+
@property (nonatomic, strong) SDAnimatedImageView *imageView2;
1516

1617
@end
1718

@@ -23,9 +24,40 @@ - (void)viewDidLoad {
2324

2425
[[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]];
2526

26-
[self.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://littlesvr.ca/apng/images/SteamEngine.webp"]];
27+
self.imageView1 = [UIImageView new];
28+
self.imageView1.contentMode = UIViewContentModeScaleAspectFit;
29+
[self.view addSubview:self.imageView1];
30+
31+
self.imageView2 = [SDAnimatedImageView new];
32+
self.imageView2.contentMode = UIViewContentModeScaleAspectFit;
33+
[self.view addSubview:self.imageView2];
34+
35+
NSURL *staticWebPURL = [NSURL URLWithString:@"https://www.gstatic.com/webp/gallery/2.webp"];
36+
NSURL *animatedWebPURL = [NSURL URLWithString:@"http://littlesvr.ca/apng/images/world-cup-2014-42.webp"];
37+
38+
[self.imageView1 sd_setImageWithURL:staticWebPURL completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
39+
if (image) {
40+
NSLog(@"%@", @"Static WebP load success");
41+
}
42+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
43+
NSData *webpData = [image sd_imageDataAsFormat:SDImageFormatWebP];
44+
if (webpData) {
45+
NSLog(@"%@", @"WebP encoding success");
46+
}
47+
});
48+
}];
49+
[self.imageView2 sd_setImageWithURL:animatedWebPURL completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
50+
if (image) {
51+
NSLog(@"%@", @"Animated WebP load success");
52+
}
53+
}];
2754
}
2855

56+
- (void)viewWillLayoutSubviews {
57+
[super viewWillLayoutSubviews];
58+
self.imageView1.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height / 2);
59+
self.imageView2.frame = CGRectMake(0, self.view.bounds.size.height / 2, self.view.bounds.size.width, self.view.bounds.size.height / 2);
60+
}
2961

3062
- (void)didReceiveMemoryWarning {
3163
[super didReceiveMemoryWarning];

Example/Screenshot/WebPDemo.png

939 KB
Loading

README.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
[![Platform](https://img.shields.io/cocoapods/p/SDWebImageWebPCoder.svg?style=flat)](http://cocoapods.org/pods/SDWebImageWebPCoder)
77
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/SDWebImage/SDWebImageWebPCoder)
88

9-
Starting with the SDWebImage 5.0 version, we moved the [libwebp](https://github.com/webmproject/libwebp) support code from the Core Repo to this stand-alone repo.
9+
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.
10+
11+
SDWebImageWebPCoder supports both WebP decoding and encoding, for Static WebP or Animated WebP as well.
1012

1113
## Requirements
1214

@@ -35,13 +37,38 @@ github "SDWebImage/SDWebImageWebPCoder"
3537

3638
## Usage
3739

40+
+ Objective-C
41+
3842
```objective-c
43+
// Add coder
3944
SDImageWebPCoder *webPCoder = [SDImageWebPCoder sharedCoder];
40-
[[SDWebImageCodersManager sharedInstance] addCoder:webPCoder];
45+
[[SDImageCodersManager sharedManager] addCoder:webPCoder];
4146

47+
// WebP image loading
4248
UIImageView *imageView;
43-
NSURL *WebPURL = ...;
44-
[imageView sd_setImageWithURL:WebPURL];
49+
NSURL *webpURL;
50+
[imageView sd_setImageWithURL:webpURL];
51+
52+
// WebP image encoding
53+
UIImage *image;
54+
NSData *webpData = [UIImage sd_imageDataAsFormat:SDImageFormatWebP];
55+
```
56+
57+
+ Swift
58+
59+
```swift
60+
// Add coder
61+
let WebPCoder = SDImageWebPCoder.shared
62+
SDImageCodersManager.shared.addCoder(WebPCoder)
63+
64+
// WebP online image loading
65+
let webpURL: URL
66+
let imageView: UIImageView
67+
imageView.sd_setImage(with: webpURL)
68+
69+
// WebP image encoding
70+
let image: UIImage
71+
let webpData = image.sd_imageData(asFormat: .WebP)
4572
```
4673

4774
## Example
@@ -50,10 +77,19 @@ To run the example project, clone the repo, and run `pod install` from the Examp
5077

5178
This is a demo to show how to use `WebP` and animated `WebP` images via `SDWebImage`.
5279

80+
## Screenshot
81+
82+
<img src="https://raw.githubusercontent.com/SDWebImage/SDWebImageWebPCoder/master/Example/Screenshot/WebPDemo.png" width="300" />
83+
84+
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)
85+
5386
## Author
5487

5588
[Bogdan Poplauschi](https://github.com/bpoplauschi)
89+
[DreamPiggy](https://github.com/dreampiggy)
5690

5791
## License
5892

5993
SDWebImageWebPCoder is available under the MIT license. See [the LICENSE file](https://github.com/SDWebImage/SDWebImageWebPCoder/blob/master/LICENSE) for more info.
94+
95+

0 commit comments

Comments
 (0)