keywind
keywind

Reputation: 1195

iOS: Display WebP image in UIWebView

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?

Upvotes: 4

Views: 4085

Answers (4)

Pelanes
Pelanes

Reputation: 3477

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)

Upvotes: 0

vikesh
vikesh

Reputation: 59

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

}

Upvotes: 0

Auryn
Auryn

Reputation: 1176

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

        })

Upvotes: 0

dpogue
dpogue

Reputation: 553

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

Upvotes: 0

Related Questions