aboutsummaryrefslogtreecommitdiff
path: root/Map/Extensions/NSImage+writePNG.swift
diff options
context:
space:
mode:
authorRuben Beltran del Rio <ruben@unlimited.pizza>2021-02-03 23:53:12 +0100
committerRuben Beltran del Rio <ruben@unlimited.pizza>2021-02-03 23:53:12 +0100
commit5e8ff4850c4827125fe12788dd5b153c4f636f48 (patch)
treef37c90338f33e7ddc84cc855a20dca1ca503476e /Map/Extensions/NSImage+writePNG.swift
parent1b85f723b48d38cf345bb9a4f3fd01aa6039b50b (diff)
Add code for first release
Diffstat (limited to 'Map/Extensions/NSImage+writePNG.swift')
-rw-r--r--Map/Extensions/NSImage+writePNG.swift25
1 files changed, 25 insertions, 0 deletions
diff --git a/Map/Extensions/NSImage+writePNG.swift b/Map/Extensions/NSImage+writePNG.swift
new file mode 100644
index 0000000..c24c0cf
--- /dev/null
+++ b/Map/Extensions/NSImage+writePNG.swift
@@ -0,0 +1,25 @@
+import Cocoa
+
+extension NSImage {
+ public func writePNG(toURL url: URL) {
+
+ guard let data = tiffRepresentation,
+ let rep = NSBitmapImageRep(data: data),
+ let imgData = rep.representation(
+ using: .png, properties: [.compressionFactor: NSNumber(floatLiteral: 1.0)])
+ else {
+
+ print(
+ "\(self.self) Error Function '\(#function)' Line: \(#line) No tiff rep found for image writing to \(url)"
+ )
+ return
+ }
+
+ do {
+ try imgData.write(to: url)
+ } catch let error {
+ print(
+ "\(self.self) Error Function '\(#function)' Line: \(#line) \(error.localizedDescription)")
+ }
+ }
+}