https://github.com/lepips/blurhashkit
Swift Package for BlurHash
https://github.com/lepips/blurhashkit
blurhash ios macos spm swift swiftpackage swiftui tvos
Last synced: about 1 month ago
JSON representation
Swift Package for BlurHash
- Host: GitHub
- URL: https://github.com/lepips/blurhashkit
- Owner: LePips
- License: mit
- Created: 2022-08-08T03:30:06.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-12-28T21:19:05.000Z (over 2 years ago)
- Last Synced: 2025-03-28T19:55:21.093Z (about 1 year ago)
- Topics: blurhash, ios, macos, spm, swift, swiftpackage, swiftui, tvos
- Language: Swift
- Homepage:
- Size: 20.5 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# BlurHashKit
Initially a port of the [BlurHash's Swift](https://github.com/woltapp/blurhash/tree/master/Swift/BlurHashKit) but rewritten with some optimizations. ~10% faster `String -> [UI|NS]Image` decoding.
Supports iOS, tvOS, watchOS, and macOS.
On Optimizations
This package tries to cache repeatedly used values as much as possible. Due to this, there may be an additional memory footprint. However, it's assumed your app has heavy use of BlurHashes, so this should be negligible.
This package makes optimizations for `(4, 3)` component shape. Using another shape may lose these optimizations, but you probably don't need to use anything else anyways.
Optimization implementations were validated with pixel comparison against the initial port.
## Usage
Decode a blurhash string directly into an image or encode an image into a BlurHash string:
```swift
// AppKit/UIKit
let image = UIImage(blurHash: "LGF5?xYk^6#M@-5c,1J5@[or[Q6.")
let image = NSImage(blurHash: "LGF5?xYk^6#M@-5c,1J5@[or[Q6.")
let blurHashString = image?.cgImage?.blurHash()
// SwiftUI
let image = Image(blurHash: "LGF5?xYk^6#M@-5c,1J5@[or[Q6.")
```
See `Examples/BlurHashExample` to see how to use BlurHash.