feat: add dimension

This commit is contained in:
dscyrescotti
2024-06-16 14:54:40 +07:00
parent f93dbdc6a8
commit 0044fd34a3
3 changed files with 11 additions and 5 deletions

View File

@@ -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)

View File

@@ -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
}
}

View File

@@ -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)
}
}