Swiftpack.co - Package - ainame/Swift-WebP


Build Status Carthage compatible

Swift Wrapper of libwebp


Swift-WebP aims to deal with image processing flexibly for WebP format in Swift unlike an image loading library; such as SDWebImage. So this library allows you to use many features libwebp has without hassles to use C API from Swift. And also you don't need to install libwebp by yourself if you install this via Carthage. This contains it inside the framework.

Support Versions:

  • libwebp: v1.0.0
  • iOS Deployment Target: 8.0
  • macOS Deployment Target: 10.11



  • [ ] Progressively encoding/decoding option
  • [ ] Animated WebP
  • [ ] support Linux build



let image = UIImage(named: "demo")
let encoder = WebPEncoder()
let queue =  DispatchQueue(label: "me.ainam.webp")

// should encode in background
queue.async {
    let data = try! encoder.encode(image, config: .preset(.picture, quality: 95))
    // using webp binary data...


let data: Data = loadWebPData()
let encoder = WebPDecoder()
let queue =  DispatchQueue(label: "me.ainam.webp")

// should decode in background
queue.async {
    var options = WebPDecoderOptions()
    options.scaledWidth = Int(originalWidth / 2)
    options.scaledHeight = Int(originalHeight / 2)
    let cgImage = try! decoder.decode(data, options: options)
    let webpImage = UIImage(cgImage: cgImage)

    DispatchQueue.main.async {
        self.imageView.image = webpImage


Please check example projects


This library won't support CocoaPods. It's difficult to create and maintain podspec files for static libraries. (But contribution for that is always welcome.)


Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate WebP into your Xcode project using Carthage, specify it in your Cartfile:

github "ainame/Swift-WebP"

Run carthage update --use-submodules to build the framework and drag the built `WebP.framework** into your Xcode project.

Don't forget to use --use-submodules flag!




Swift-WebP is available under the MIT license. See the LICENSE file for more info.


Stars: 71
Help us keep the lights on


Used By

Total: 0


v0.0.8 - Jan 10, 2019

v0.0.7 - Jan 10, 2019

v0.0.6 - Oct 2, 2018

Support Xcode10 and Swift4.2 (nothing changed at all)

v0.0.5 - Aug 20, 2018


@ainame decided that Swift-WebP project won't support CocoaPods. Because of the difficulty to create a podspec that support clang module and using git submodules.


  • Update libwebp v0.60 -> v1.0.0
  • Now WebPEncoder supports iOS platform

Bug fix

  • Handle use_argb flag properly here

Breaking changes

  • WebPSimple.encode (no longer need as it is only needed for me to try encoding on iOS platform)

v0.0.4 - Feb 7, 2017

  • fix compile option for iOS or macOS