4 Copyright (C) 2024 Rubén Beltrán del Río
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see https://captura.tranquil.systems.
19 import UniformTypeIdentifiers
22 static func render(_ images: [CGImage], at fps: Int, to url: URL) async {
23 let framedelay = String(format: "%.3f", 1.0 / Double(fps))
24 let fileProperties = [
25 kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: 0]
28 kCGImagePropertyGIFDictionary as String: [
29 kCGImagePropertyGIFUnclampedDelayTime as String: framedelay
32 let cfURL = url as CFURL
33 if let destination = CGImageDestinationCreateWithURL(
34 cfURL, UTType.gif.identifier as CFString, images.count, nil)
36 CGImageDestinationSetProperties(destination, fileProperties as CFDictionary?)
38 CGImageDestinationAddImage(destination, image, gifProperties as CFDictionary?)
40 CGImageDestinationFinalize(destination)