mirror of
https://github.com/GayPizzaSpecifications/stable-diffusion-rpc.git
synced 2025-08-04 05:51:32 +00:00
Formatting, linting, and hopefully a CI build.
This commit is contained in:
22
Sources/StableDiffusionCore/ImageExtensions.swift
Normal file
22
Sources/StableDiffusionCore/ImageExtensions.swift
Normal file
@ -0,0 +1,22 @@
|
||||
import CoreImage
|
||||
import Foundation
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
extension CGImage {
|
||||
func toPngData() throws -> Data {
|
||||
guard let data = CFDataCreateMutable(nil, 0) else {
|
||||
throw SdCoreError.imageEncode
|
||||
}
|
||||
|
||||
guard let destination = CGImageDestinationCreateWithData(data, "public.png" as CFString, 1, nil) else {
|
||||
throw SdCoreError.imageEncode
|
||||
}
|
||||
|
||||
CGImageDestinationAddImage(destination, self, nil)
|
||||
if CGImageDestinationFinalize(destination) {
|
||||
return data as Data
|
||||
} else {
|
||||
throw SdCoreError.imageEncode
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user