kevin-lxh / WebP-Swift

Simple iOS Swift 3 WebP decoder to UIImage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WebP-Swift

Simple iOS Swift WebP decoder to UIImage. The project use a standalone version of WebP library, without the use of cocoapods (or other dependency managers) to avoid problems with swift dynamic libraries.

Installation

  • Download the precompiled library from Google Developers
  • Unzip the .tar.gz file and rename it: "WebP.framework" and put it in the project folder
  • Open Xcode project, target 'app', Build Phases and click "Other Framework" in Link Binary with Libraries
  • Select 'WebP.framework'
  • Add in your bridging header the reference to the WebP framework:
#import "webp/decode.h"
  • Include 'UIImage+WebPDecoder.swift' in your project
  • Enjoy WebP Decoder 😃

Usage

Converting from WebP

//Example
let url = URL(string: "https://www.gstatic.com/webp/gallery3/3_webp_ll.webp")!

//Simple Usage without options
let imageWithURL = UIImage(webpWithURL: url)

//Simple Usage Example with options
let options: [String : Int32] = ["no_fancy_upsampling":1,"bypass_filtering":1,"use_threads":1]
let imageWithURLandOptions = UIImage(webpWithURL: url, andOptions: options)

Converting from different sources

//From URL
let image = UIImage(webpWithURL: URL)
let image = UIImage(webpWithURL: URL, andOptions: [String:Int32])

//From path
let image = UIImage(webpWithPath: String)
let image = UIImage(webpWithPath: String, andOptions: [String:Int32])

//From data
let image = UIImage(webpWithData: NSData)
let image = UIImage(webpWithData: NSData, andOptions: [String:Int32])

Credits

About

Simple iOS Swift 3 WebP decoder to UIImage

License:MIT License


Languages

Language:C 94.2%Language:Swift 5.7%Language:Objective-C 0.1%