diff --git a/Memola/Canvas/Contexts/GraphicContext.swift b/Memola/Canvas/Contexts/GraphicContext.swift index 38db14e..61e811b 100644 --- a/Memola/Canvas/Contexts/GraphicContext.swift +++ b/Memola/Canvas/Contexts/GraphicContext.swift @@ -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) diff --git a/Memola/Canvas/Tool/Core/Tool.swift b/Memola/Canvas/Tool/Core/Tool.swift index 1901c9d..27556dc 100644 --- a/Memola/Canvas/Tool/Core/Tool.swift +++ b/Memola/Canvas/Tool/Core/Tool.swift @@ -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 } } diff --git a/Memola/Features/Memo/PhotoPreview/PhotoItem.swift b/Memola/Features/Memo/PhotoPreview/PhotoItem.swift index a857da5..d69cd3b 100644 --- a/Memola/Features/Memo/PhotoPreview/PhotoItem.swift +++ b/Memola/Features/Memo/PhotoPreview/PhotoItem.swift @@ -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) + } }