mirror of
https://github.com/dscyrescotti/Memola.git
synced 2026-03-26 03:11:19 +01:00
feat: add dimension
This commit is contained in:
@@ -305,7 +305,7 @@ extension GraphicContext {
|
||||
// MARK: - Photo
|
||||
extension GraphicContext {
|
||||
func insertPhoto(at point: CGPoint, photoItem: PhotoItem) {
|
||||
let size = CGSize(width: 100, height: 100)
|
||||
let size = photoItem.dimension
|
||||
let origin = point
|
||||
let bounds = [origin.x - size.width / 2, origin.y - size.height / 2, origin.x + size.width / 2, origin.y + size.height / 2]
|
||||
let photo = Photo(url: photoItem.id, size: size, origin: origin, bounds: bounds, createdAt: .now, bookmark: photoItem.bookmark)
|
||||
|
||||
@@ -126,16 +126,14 @@ public class Tool: NSObject, ObservableObject {
|
||||
guard let directory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first else {
|
||||
return nil
|
||||
}
|
||||
let fileName = "\(UUID().uuidString)-\(Date.now.timeIntervalSince1970)"
|
||||
let fileName = "\(UUID().uuidString)-\(Int(Date.now.timeIntervalSince1970))"
|
||||
let folder = directory.appendingPathComponent(canvasID.uriRepresentation().lastPathComponent, conformingTo: .folder)
|
||||
|
||||
if folder.startAccessingSecurityScopedResource(), !fileManager.fileExists(atPath: folder.path()) {
|
||||
if !fileManager.fileExists(atPath: folder.path()) {
|
||||
do {
|
||||
try fileManager.createDirectory(at: folder, withIntermediateDirectories: true)
|
||||
folder.stopAccessingSecurityScopedResource()
|
||||
} catch {
|
||||
NSLog("[Memola] - \(error.localizedDescription)")
|
||||
folder.stopAccessingSecurityScopedResource()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,12 @@ struct PhotoItem: Identifiable, Equatable {
|
||||
var id: URL
|
||||
let image: UIImage
|
||||
let bookmark: Data
|
||||
|
||||
var dimension: CGSize {
|
||||
let size = image.size
|
||||
let maxSize = max(size.width, size.height)
|
||||
let width = size.width * 200 / maxSize
|
||||
let height = size.height * 200 / maxSize
|
||||
return CGSize(width: width, height: height)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user