Initial Commit

This commit is contained in:
2023-04-22 14:52:27 -07:00
commit 2759c8d7fb
16 changed files with 1806 additions and 0 deletions

View File

@ -0,0 +1,22 @@
import Foundation
import CoreImage
import UniformTypeIdentifiers
extension CGImage {
func toPngData() throws -> Data {
guard let data = CFDataCreateMutable(nil, 0) else {
throw SdServerError.imageEncode
}
guard let destination = CGImageDestinationCreateWithData(data, "public.png" as CFString, 1, nil) else {
throw SdServerError.imageEncode
}
CGImageDestinationAddImage(destination, self, nil)
if CGImageDestinationFinalize(destination) {
return data as Data
} else {
throw SdServerError.imageEncode
}
}
}