Swiftpack.co - awxkee/avif.swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by awxkee.
awxkee/avif.swift 1.1.1
Fast encoding and decoding AVIF in Swift
⭐️ 3
🕓 Yesterday
iOS macOS macCatalyst
.package(url: "https://github.com/awxkee/avif.swift.git", from: "1.1.1")

avif.swift

What's This?

avif.swift the package to easy compress UIImage to AVIF and decompress AVIF to UIImage

Library uses precompiled libaom and dav1d to ensure in fast encoding/decoding
Main aim of the project is to use AVIF image in iOS etc with usable speed and convenience

Supports animated AVIF's with realtime FPS like 24+ Also supports encoding animated AVIF's

Precompiled for iOS 14+, Mac OS 12+, Mac Catalyst 14+

Installation

Swift Package Manager

Go to File / Swift Packages / Add Package Dependency… and enter package repository URL https://github.com/awxkee/avif.swift.git, then select the latest master branch at the time of writing.

Usage

// Decompress data
let uiImage: UIImage? = AVIFDecoder().decode(Data(), sampleSize: .zero) // or any max CGSize of image
// Compress
let data: Data = try AVIFEncoder().encode(image: UIImage())

// Decode animated
let animatedDecoder = AnimatedDecoder(withData: Data())
let frame: CGImage = try animatedDecoder.get(frame: 1)
let image: UIImage = try animatedDecoder.getImage(frame: 1) 

// Encode animation
import avifc

let animatedEncoder = AVIFAnimatedEncoder()
animatedEncoder.create()
try animatedEncoder.addImage(UIImage(), duration: 250)
let encodedData = animatedEncoder.encode()

Nuke Plugin

If you wish to use AVIF with Nuke you may add avifnuke library to project and activate the plugin on app init

import avifnuke

AVIFNukePlugin.enable()

let imageView = UIImageView()
let avifimageURL = URL(string: "https://bestavifdomain.com/sample.avif")!
Nuke.loadImage(with: url, into: imageView)

Currently, avif nuke plugin do not support animated avifs so you have to do it yourself

TODO

  • ☐ Tests
  • ☐ Some examples

GitHub

link
Stars: 3
Last commit: Yesterday
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Dependencies

Release Notes

Release 1.1.1
Yesterday

Migrated to latest libdav1d

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics