Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting cursor images from cape file #246

Open
llsc12 opened this issue Sep 21, 2024 · 1 comment
Open

Exporting cursor images from cape file #246

llsc12 opened this issue Sep 21, 2024 · 1 comment

Comments

@llsc12
Copy link

llsc12 commented Sep 21, 2024

Dragging images out of the editor into a folder doesn't copy it but rather removes it and there seems to be no way to export images as a result. Thanks in advance.

@llsc12
Copy link
Author

llsc12 commented Sep 21, 2024

import PlaygroundSupport
import Foundation

// put file.cape in the Resources folder of the macos playground

let fileURL = Bundle.main.url(forResource: "file", withExtension: "cape")!

let dec = PropertyListDecoder()

struct CapeFile: Codable {
  let Author: String
  let Cursors: [String: Cursor]
  
  struct Cursor: Codable {
    let Representations: [Data]
  }
}

let cape = try dec.decode(CapeFile.self, from: Data(contentsOf: fileURL))

// this iterates through capes and writes the tiff files
// saved to ~/Desktop/dumped/
try cape.Cursors.forEach { (key: String, value: CapeFile.Cursor) in
  let loc = URL.desktopDirectory.appendingPathComponent("dumped").appendingPathComponent(key).appendingPathExtension("tiff")
  try FileManager.default.createDirectory(at: URL.desktopDirectory.appendingPathComponent("dumped"), withIntermediateDirectories: true)
  try value.Representations.first?.write(to: loc)
}

In case anyone needs this, hope it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant