https://github.com/fwcd/swift-gif
Cross-platform GIF encoder and decoder for Swift
https://github.com/fwcd/swift-gif
animated-gif hacktoberfest linux lzw-compression swift
Last synced: 6 months ago
JSON representation
Cross-platform GIF encoder and decoder for Swift
- Host: GitHub
- URL: https://github.com/fwcd/swift-gif
- Owner: fwcd
- License: mit
- Created: 2020-09-29T21:12:42.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-02-17T01:17:17.000Z (8 months ago)
- Last Synced: 2025-04-14T01:18:00.128Z (6 months ago)
- Topics: animated-gif, hacktoberfest, linux, lzw-compression, swift
- Language: Swift
- Homepage: https://fwcd.github.io/swift-gif/documentation/gif
- Size: 3.02 MB
- Stars: 19
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GIF Coder for Swift
[](https://github.com/fwcd/swift-gif/actions/workflows/build.yml)
[](https://fwcd.github.io/swift-gif/documentation/gif)A lightweight LZW encoder and decoder for animated GIFs written in pure Swift, thus running on any platform, including Linux.
## Example
```swift
// Create a new GIF
var gif = GIF(width: 300, height: 300)// Add some frames for the animation
for i in 0..<20 {
let image = try CairoImage(pngFilePath: "frame\(i).png")
gif.frames.append(.init(image: image, delayTime: 100))
}// Encode the GIF to a byte buffer
let data = try gif.encoded()
```## Technical Details
GIF encoding is more computationally intensive than decoding. It can become a bottleneck when GIF is used as a video codec and serialization must happen in real-time. Therefore, multicore CPU is used to accelerate the encoding of animated GIFs. All the animation frames are gathered into one `Array`, which is then divided among all CPU cores in the system.
## System Dependencies
* Swift 5.10+
* Cairo, see [swift-graphics](https://github.com/fwcd/swift-graphics)