// // ProcessThumbnal.swift // ProcessCheckFile // // Created by 朱东勇 on 2022/12/9. // import Foundation import QuickLook import QuickLookUI import QuickLookThumbnailing let generator = QLThumbnailGenerator.shared class ProcessThumbnal : NSObject { class func process(_ filePath:String, desPath:String) -> Bool { let kDefaultThumbnailSize = CGSizeMake(1000.0, 1000.0) return process(filePath, desPath: desPath, outputSize: kDefaultThumbnailSize) } class func process(_ filePath:String, desPath:String, outputSize:CGSize) -> Bool { var didFinished = false let semaphore = DispatchSemaphore(value: 0) let url = URL.init(filePath: filePath) generator.generateRepresentations(for: QLThumbnailGenerator.Request.init(fileAt: url, size: CGSizeMake(1024.0, 10240.0), scale: 1.0, representationTypes: QLThumbnailGenerator.Request.RepresentationTypes.thumbnail), update: { (representation, type, error) in let image = representation!.nsImage as NSImage if nil != image { didFinished = true try? image.tiffRepresentation?.write(to: URL.init(filePath: desPath)) } semaphore.signal() }) semaphore.wait() return didFinished } }