While using Google WebP image format in my iOS App, I find Google's library is good at displaying WebP image in native code.
Now I want to use WebP in my webapp too, but UIWebView doesn't support. Any ideas to implement it?
If you are using Cordova/Phonegap, there is a plugin to add WebP support to UIWebView. If you're not using Cordova, you should be able to use the same mechanism just without the plugin registration.
You can use the Pod https://github.com/rs/SDWebImage
There is it really easy to load WebP Images from the Web
With Swift:
SDWebImageManager.shared().loadImage(with: url, options: .highPriority, progress: nil, completed: {(resultSet) in
YOURWEBVIEW.image = resultSet.0
})
You can use the Pod https://github.com/rs/SDWebImage
POD:-pod 'SDWebImage/WebP'
With Swift 4.2:
let thumbimgurl = URL(string: "https://res.cloudinary.com/demo/image/upload/w_300/sample.webp")
SDWebImageManager.shared().loadImage(with: thumbimgurl, options: .highPriority, progress: nil) { (DisplayUIImage, ImageSize, Error, SDImageCacheType, ImageBool, ImageURL) in
self.MyImageDisplayImageView.image = DisplayUIImage
}
If your resource is into your bundle, you can do it in this way with SDWebImage library:
let webpData: Data = try Data(contentsOf: Bundle.main.url(forResource: "your_resource_name", withExtension:"webp")!)
imageView.image = SDImageWebPCoder.shared.decodedImage(with: webpData, options: nil)