All Projects → TimOliver → WebPKit

TimOliver / WebPKit

Licence: MIT License
A framework that extends a variety of Cocoa APIs with capabilities for encoding and decoding WebP files for all of Apple's platforms.

Programming Languages

swift
15916 projects
shell
77523 projects
objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to WebPKit

Swiftyattributes
A Swifty API for attributed strings
Stars: ✭ 1,303 (+4393.1%)
Mutual labels:  tvos, watchos, cocoa
BlockiesSwift
Unique blocky identicons generator for Swift
Stars: ✭ 53 (+82.76%)
Mutual labels:  tvos, watchos, cocoa
Sdwebimagewebpcoder
A WebP coder plugin for SDWebImage, use libwebp
Stars: ✭ 101 (+248.28%)
Mutual labels:  tvos, watchos, webp
Swiftui
A collaborative list of awesome SwiftUI resources. Feel free to contribute!
Stars: ✭ 774 (+2568.97%)
Mutual labels:  tvos, watchos, uikit
Invalidating
Backports the new @invalidating property wrapper to older platforms
Stars: ✭ 53 (+82.76%)
Mutual labels:  tvos, uikit, appkit
Sdwebimageswiftui
SwiftUI Image loading and Animation framework powered by SDWebImage
Stars: ✭ 844 (+2810.34%)
Mutual labels:  tvos, watchos, webp
Articles Zh Hans
Articles for NSHipster.cn
Stars: ✭ 113 (+289.66%)
Mutual labels:  tvos, watchos, cocoa
Swifterswift
A handy collection of more than 500 native Swift extensions to boost your productivity.
Stars: ✭ 10,706 (+36817.24%)
Mutual labels:  tvos, watchos, uikit
WWDCNotes
WWDCNotes.com content
Stars: ✭ 343 (+1082.76%)
Mutual labels:  tvos, watchos, cocoa
articles-ko
Articles for NSHipster.co.kr
Stars: ✭ 18 (-37.93%)
Mutual labels:  tvos, watchos, cocoa
Sentry Cocoa
The official Sentry SDK for iOS, tvOS, macOS, watchOS
Stars: ✭ 370 (+1175.86%)
Mutual labels:  tvos, watchos, cocoa
SwiftCurrent
A library for managing complex workflows in Swift
Stars: ✭ 286 (+886.21%)
Mutual labels:  tvos, watchos, uikit
Nshipster.com
A journal of the overlooked bits in Objective-C, Swift, and Cocoa. Updated weekly.
Stars: ✭ 280 (+865.52%)
Mutual labels:  tvos, watchos, cocoa
Articles
Articles for NSHipster.com
Stars: ✭ 1,166 (+3920.69%)
Mutual labels:  tvos, watchos, cocoa
Wwdc Notes
WWDCNotes.com content ✨
Stars: ✭ 183 (+531.03%)
Mutual labels:  tvos, watchos, cocoa
RFKit
Toolkit for daily Cocoa development. Since 2012.
Stars: ✭ 20 (-31.03%)
Mutual labels:  tvos, watchos, uikit
Driftwood
Driftwood is a DSL to make Auto Layout easy on iOS, tvOS and macOS.
Stars: ✭ 14 (-51.72%)
Mutual labels:  tvos, uikit, appkit
SPConfetti
Show the confetti only when the user is having fun, and if not having fun, don't show it.
Stars: ✭ 187 (+544.83%)
Mutual labels:  tvos, uikit
Hostess.swift
A Swift implementation of NSHost that works on iOS, OS X and tvOS. Hostess.swift is safe to use in a framework because it does not require a bridging header. Hostess is Swift 4.0 (or newer) only and replaces the Swift 2.x only Host.swift.
Stars: ✭ 27 (-6.9%)
Mutual labels:  tvos, watchos
Jsonify
♨️A delightful JSON parsing framework.
Stars: ✭ 42 (+44.83%)
Mutual labels:  tvos, watchos

WebPKit

WebPKit running on various devices

CI Version Carthage compatible GitHub license Platform

WebPKit is an open source Swift framework that wraps around Google's WebP library to provide a native-feeling Cocoa API for working with WebP image files on all of Apple's platforms.

WebPKit works by extending certain Cocoa classes to enable decoding WebP image data from disk, or encoding WebP image data from memory. It also provides additional functionality such as being able to verify the contents of a WebP file before decoding, as well as using WebP's decoding features to enable custom sizing.

Features

  • Read image files in the WebP format.
  • Write in-memory images to the WebP format.
  • Supports all of Apple's platforms (including Mac Catalyst).
  • Additional convenience methods for quickly verifying WebP data before decoding.
  • Decode WebP images directly to custom sizes (Good for saving memory)
  • 100% Swift, and fully unit-tested.

Requirements

  • iOS: 9.0 and above
  • macOS: 10.9 and above
  • tvOS: 9.0 and above
  • watchOS: 2.0 and above

When installing manually, you will also need Google's WebP C library as well. Precompiled static binaries are available at the Cocoa-WebP repo.

Usage

WebPKit provides extensions to a variety of popular Cocoa classes in order to natively provide WebP format support.

Verifying a WebP image file

WebPKit provides a variety of methods to check the contents of a file or some data to see if it is a valid WebP file.

import WebPKit 

// Check a `Data` object to see if it contains WebP data
let webpData = Data(...) 
print(webpData.isWebP)

// Check a file on disk to see if it is a WebP file
let url = URL(...) 
print(url.isWebP)

// Retrieve the pixel size of the image without decoding it
let size = CGImage.sizeOfWebP(with: Data())

Decoding a WebP image

WebPKit performs decoding of WebP image data at the CGImage level, and then provides convenience initialisers for UIImage and NSImage on iOS-based platforms and macOS respectively.

iOS / iPadOS / tvOS / watchOS

import WebPKit 

// Load from data in memory
let webpImage = UIImage(webpData: Data())

// Load from disk
let webpImage = UIImage(contentsOfWebPFile: URL())
 
// Load from resource bundle
let webpImage = UIImage.webpNamed("MyWebPImage")

macOS

import WebPKit 

// Load from data in memory
let webpImage = NSImage(webpData: Data())

// Load from disk
let webpImage = NSImage(contentsOfWebPFile: URL())
 
// Load from resource bundle
let webpImage = NSImage.webpNamed("MyWebPImage")

Installation

CocoaPods

Add the following to your Podfile:

pod 'WebPKit'
Carthage

Carthage support is coming soon. Stay tuned!

Swift Package Manager

SPM support is coming soon. Stay tuned!

Manual Installation
1. Download this repository.
2. Copy the `WebPKit` folder to your Xcode project.
3. Download the precompiled WebP binary from [the Cocoa-WebP repo](https://github.com/TimOliver/WebP-Cocoa) for your desired platform.
4. Drag that framework into your Xcode project.

Why Build This?

Support for WebP image files had been a growing feature request in my comic reader app iComics for a number of years. With iComics being in Objective-C, I was able to use one of the many libraries on GitHub out there to easily support it.

But while that was the case for Objective-C, while I've been working on iComics 2, I started to realise that there still wasn't a great amount of WebP support for Swift, as well as Apple's modern platforms and features in general.

Google's own precompiled WebP binaries don't support either Swift or Mac Catalyst, and while I found a few different WebP Swift libraries out there, none covered all of the requirements that I was hoping for (Things like CocoaPods support, accurate alpha channel control, and decoding at intermediate sizes).

For a feature that will be an extremely fundamental pillar in iComics 2, I decided that it would be worth the time and investment to go back and make a really good WebP framework from scratch, that followed the API design of Apple's frameworks for easy integration, but also gave me the control to include all of the advanced features I need from the start.

I'm incrdedibly happy with how this framework turned out. It turns out it was no where near as much code as I was expecting, and it all fit nicely as extensions on existing Apple classes. Moving forward, I hope this framework can be valuable for other Apple developers as well.

Credits

WebPKit was created by Tim Oliver.

A huge shout-out also goes to the SDWebImage team for maintaining CocoaPods and Carthage releases for WebP all this time as well.

License

WebPKit is licensed under the MIT License. Please see the LICENSE file for more details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].