File tree 2 files changed +17
-1
lines changed
Example/SDWebImageWebPCoderExample
2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -42,8 +42,10 @@ - (void)viewDidLoad {
42
42
NSLog (@" %@ " , @" Static WebP load success" );
43
43
}
44
44
dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
45
- NSData *webpData = [image sd_imageDataAsFormat: SDImageFormatWebP];
45
+ NSUInteger maxFileSize = 4096 ;
46
+ NSData *webpData = [SDImageWebPCoder.sharedCoder encodedDataWithImage: image format: SDImageFormatWebP options: @{SDImageCoderEncodeMaxFileSize : @(maxFileSize)}];
46
47
if (webpData) {
48
+ NSCAssert (webpData.length <= maxFileSize, @" WebP Encoding with max file size limit works" );
47
49
NSLog (@" %@ " , @" WebP encoding success" );
48
50
}
49
51
});
Original file line number Diff line number Diff line change @@ -182,6 +182,20 @@ - (void)test34StaticImageNotCreateCGContext {
182
182
XCTAssert (canvas == NULL );
183
183
}
184
184
185
+ - (void )test45WebPEncodingMaxFileSize {
186
+ NSURL *staticWebPURL = [[NSBundle bundleForClass: [self class ]] URLForResource: @" TestImageStatic" withExtension: @" webp" ];
187
+ NSData *data = [NSData dataWithContentsOfURL: staticWebPURL];
188
+ UIImage *image = [UIImage sd_imageWithWebPData: data];
189
+ NSData *dataWithNoLimit = [SDImageWebPCoder.sharedCoder encodedDataWithImage: image format: SDImageFormatWebP options: nil ];
190
+ XCTAssertNotNil (dataWithNoLimit);
191
+ NSUInteger maxFileSize = 8192 ;
192
+ NSData *dataWithLimit = [SDImageWebPCoder.sharedCoder encodedDataWithImage: image format: SDImageFormatWebP options: @{SDImageCoderEncodeMaxFileSize : @(maxFileSize)}];
193
+ XCTAssertNotNil (dataWithLimit);
194
+ XCTAssertGreaterThan (dataWithNoLimit.length , dataWithLimit.length );
195
+ XCTAssertGreaterThan (dataWithNoLimit.length , maxFileSize);
196
+ XCTAssertLessThanOrEqual (dataWithLimit.length , maxFileSize);
197
+ }
198
+
185
199
@end
186
200
187
201
@implementation SDWebImageWebPCoderTests (Helpers)
You can’t perform that action at this time.
0 commit comments