- func filename() -> String {
- let dateFormatter = DateFormatter()
- dateFormatter.dateStyle = .medium
- dateFormatter.timeStyle = .medium
- dateFormatter.locale = Locale.current
- let dateString = dateFormatter.string(from: Date()).replacingOccurrences(of: ":", with: ".")
-
- return "Captura \(dateString)"
- }
-
- func createGif(url: URL) async {
-
-
- let outputFormatsSetting = OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "outputFormats")) ?? .all
- if !outputFormatsSetting.shouldSaveGif() {
- return
- }
-
- let framedelay = String(format: "%.3f", 1.0 / Double(fps))
- let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: 0]]
- let gifProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFUnclampedDelayTime as String: framedelay]]
- let cfURL = url as CFURL
- if let destination = CGImageDestinationCreateWithURL(cfURL, UTType.gif.identifier as CFString, images.count, nil) {
- CGImageDestinationSetProperties(destination, fileProperties as CFDictionary?)
- for image in images {
- CGImageDestinationAddImage(destination, image, gifProperties as CFDictionary?)
- }
- CGImageDestinationFinalize(destination)
- }
- }