1 import UniformTypeIdentifiers
6 static func render(_ images: [CGImage], at fps: Int, to url: URL) async {
7 let framedelay = String(format: "%.3f", 1.0 / Double(fps))
8 let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: 0]]
9 let gifProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFUnclampedDelayTime as String: framedelay]]
10 let cfURL = url as CFURL
11 if let destination = CGImageDestinationCreateWithURL(cfURL, UTType.gif.identifier as CFString, images.count, nil) {
12 CGImageDestinationSetProperties(destination, fileProperties as CFDictionary?)
14 CGImageDestinationAddImage(destination, image, gifProperties as CFDictionary?)
16 CGImageDestinationFinalize(destination)