mirror of
https://github.com/dscyrescotti/Memola.git
synced 2026-04-25 01:58:52 +02:00
feat: add dimension
This commit is contained in:
@@ -305,7 +305,7 @@ extension GraphicContext {
|
|||||||
// MARK: - Photo
|
// MARK: - Photo
|
||||||
extension GraphicContext {
|
extension GraphicContext {
|
||||||
func insertPhoto(at point: CGPoint, photoItem: PhotoItem) {
|
func insertPhoto(at point: CGPoint, photoItem: PhotoItem) {
|
||||||
let size = CGSize(width: 100, height: 100)
|
let size = photoItem.dimension
|
||||||
let origin = point
|
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 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)
|
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 {
|
guard let directory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first else {
|
||||||
return nil
|
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)
|
let folder = directory.appendingPathComponent(canvasID.uriRepresentation().lastPathComponent, conformingTo: .folder)
|
||||||
|
|
||||||
if folder.startAccessingSecurityScopedResource(), !fileManager.fileExists(atPath: folder.path()) {
|
if !fileManager.fileExists(atPath: folder.path()) {
|
||||||
do {
|
do {
|
||||||
try fileManager.createDirectory(at: folder, withIntermediateDirectories: true)
|
try fileManager.createDirectory(at: folder, withIntermediateDirectories: true)
|
||||||
folder.stopAccessingSecurityScopedResource()
|
|
||||||
} catch {
|
} catch {
|
||||||
NSLog("[Memola] - \(error.localizedDescription)")
|
NSLog("[Memola] - \(error.localizedDescription)")
|
||||||
folder.stopAccessingSecurityScopedResource()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,4 +12,12 @@ struct PhotoItem: Identifiable, Equatable {
|
|||||||
var id: URL
|
var id: URL
|
||||||
let image: UIImage
|
let image: UIImage
|
||||||
let bookmark: Data
|
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