High-performance animation image library for Swift.
AnimatedImage provides a fast, memory-aware pipeline to render animated images (APNG, GIF, WebP) on Apple platforms. The public AnimatedImage module re-exports platform and SwiftUI layers so you can import AnimatedImage and use it from UIKit and SwiftUI. Heavy processing is kept off the main thread.
let package = Package(
dependencies: [
.package(url: "https://github.com/noppefoxwolf/AnimatedImage", from: "0.0.14")
],
targets: [
.target(
name: "YourTarget",
dependencies: [
.product(name: "AnimatedImage", package: "AnimatedImage")
]
)
]
)AnimatedImage uses AnimatedImageProvider to pre-decode and cache animation frames for optimal performance. It dynamically optimizes frame processing based on drawing size and timing to prevent excessive cache usage. The entire processing pipeline is designed to operate independently of MainActor, ensuring smooth UI performance.
import AnimatedImage
let imageView = AnimatedImageView(frame: .zero)
let image = APNGImage(data: data) // or GifImage(data: data), WebPImage(data: data)
imageView.image = image
imageView.startAnimating()import AnimatedImage
struct ContentView: View {
@State var image = GifImage(data: data)
var body: some View {
AnimatedImagePlayer(image: image) // .init(image:contentMode:) supports .fit/.fill
}
}Control memory, size, quality, and processing priority using AnimatedImageProviderConfiguration.
-
UIKit
let imageView = AnimatedImageView(frame: .zero) imageView.configuration = .default // .default, .performance, .unlimited imageView.contentMode = .scaleAspectFill imageView.image = GifImage(data: data) imageView.startAnimating()
-
SwiftUI
let config: AnimatedImageProviderConfiguration = .default var body: some View { AnimatedImagePlayer(image: GifImage(data: data)) .environment(\.animatedImageProviderConfiguration, config) }
All heavy processing is performed off the main thread, keeping your UI responsive.
Supports APNG, GIF, and WebP animated formats.
Automatically adjusts playback quality based on available resources.
Synchronizes frame updates for smooth animation playback.
Create your own animated images by conforming to the AnimatedImage protocol:
public final class ManualAnimatedImage: AnimatedImage, @unchecked Sendable {
public let name: String
public let imageCount: Int
private let images: [CGImage]
public init(name: String = UUID().uuidString, images: [CGImage]) {
self.name = name
self.images = images
self.imageCount = images.count
}
public func delayTime(at index: Int) -> Double {
0.1
}
public func image(at index: Int) -> CGImage? {
images[index]
}
}- Swift 6.1+
- iOS 16.0+
- macOS 14.0+
- visionOS 1.0+
The library consists of multiple internal modules unified under a single product:
AnimatedImageCore: Core animation logic and image processing- Image decoders for APNG, GIF, and WebP
AnimatedImageProviderfor animation caching and frame management- Image processing and timing calculations
- Platform-specific modules:
_UIKit_AnimatedImage: UIKit support withAnimatedImageView_AppKit_AnimatedImage: macOS support (in development)_SwiftUI_AnimatedImage: SwiftUI integration withAnimatedImagePlayer
UpdateLink: Display link and frame timing control
Notes:
Sources/AnimatedImage/is the public API that re-exports platform layers and includesResources/PrivacyInfo.xcprivacy.UpdateLinkusesUIUpdateLinkon iOS 18+/visionOS 2+ and aCADisplayLinkbackport otherwise.
- Build:
swift build(use-c releasefor optimized builds) - Test:
swift test- Filter:
swift test --filter ImageProcessorTests
- Filter:
- Xcode project (optional):
swift package generate-xcodeproj - Example local demo: open
Playground.swiftpmin Xcode and run.
- Indentation: 4 spaces; line length: 100; ordered imports. See
.swift-format. - Format:
swift format --configuration .swift-format --in-place Sources Tests - Naming: Types/protocols UpperCamelCase; methods/vars lowerCamelCase.
- Framework: Swift Testing (
import Testing,@Suite,@Test). - Scope: Focus on core processing (timing, decimation, image ops). Add mocks for images where needed.
- CI: GitHub Actions runs on macOS 15 with Xcode 16.4; ensure tests pass there.
AnimatedImage is available under the MIT license. See the LICENSE file for more info.



