File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
Example/SDWebImageWebPCoderExample Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -42,8 +42,10 @@ - (void)viewDidLoad {
4242 NSLog (@" %@ " , @" Static WebP load success" );
4343 }
4444 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)}];
4647 if (webpData) {
48+ NSCAssert (webpData.length <= maxFileSize, @" WebP Encoding with max file size limit works" );
4749 NSLog (@" %@ " , @" WebP encoding success" );
4850 }
4951 });
Original file line number Diff line number Diff line change @@ -182,6 +182,20 @@ - (void)test34StaticImageNotCreateCGContext {
182182 XCTAssert (canvas == NULL );
183183}
184184
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+
185199@end
186200
187201@implementation SDWebImageWebPCoderTests (Helpers)
You can’t perform that action at this time.
0 commit comments