4

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
keywind
  • 1,135
  • 14
  • 24

4 Answers4

0

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.

https://github.com/dpogue/cordova-plugin-webp

dpogue
  • 553
  • 5
  • 7
0

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

        })
Auryn
  • 1,117
  • 1
  • 13
  • 37
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

}
vikesh
  • 59
  • 1
  • 3
0

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)
Pelanes
  • 3,451
  • 1
  • 34
  • 32