Search code examples
iossdwebimagewebp

How to load a webp image with SDWebImage?


I'm using SDWebImage to load images in my iOS app and I now want to use the webp format.

Here's my first try :

NSURL *url = [NSURL URLWithString:@"http://www.gstatic.com/webp/gallery/2.webp"];

[self.imageView setImageWithURL:url
               placeholderImage:nil
                        options:SDWebImageProgressiveDownload
 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {

     if (error) {

         UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

         [av show];
     }
 }];

It would work perfectly if the image was a jpeg (I tried) but with a webp it doesn't. The first time I call this code the error is :

Downloaded image has 0 pixels

Then the error turns to :

The operation couldn't be completed. (NSURLErrorDomain error -1100.)

What's wrong?


Solution

  • Actually the code above should work but the webp support is disabled by default in the library.

    Adding SD_WEBP=1 in the preprocessor macros of the sdwebimage target (in build settings) will enable webp support