From 902c4b08c4e4c8c859387f5401d9960bd8884aff Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Wed, 25 Oct 2023 12:38:16 +0200 Subject: [PATCH] Scale images to smaller size --- Caps/Data/Database.swift | 2 -- Caps/Data/ImageCache.swift | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Caps/Data/Database.swift b/Caps/Data/Database.swift index a26b692..dea54d2 100644 --- a/Caps/Data/Database.swift +++ b/Caps/Data/Database.swift @@ -5,8 +5,6 @@ import CryptoKit final class Database: ObservableObject { - private let imageCompressionQuality: CGFloat = 0.3 - @AppStorage("classifier") private var storedLocalClassifierVersion = 0 { didSet { localClassifierVersion = storedLocalClassifierVersion } diff --git a/Caps/Data/ImageCache.swift b/Caps/Data/ImageCache.swift index f68cdb1..7a8f833 100644 --- a/Caps/Data/ImageCache.swift +++ b/Caps/Data/ImageCache.swift @@ -17,6 +17,8 @@ final class ImageCache: ObservableObject { private let imageQuality: CGFloat = 0.3 + private let imageSize: CGSize = .init(width: 360, height: 360) + @Published private(set) var imageCount = 0 @@ -41,7 +43,7 @@ final class ImageCache: ObservableObject { @discardableResult func save(_ image: UIImage, for cap: CapImage) -> Bool { - guard let data = image.jpegData(compressionQuality: imageQuality) else { + guard let data = image.resize(to: imageSize).jpegData(compressionQuality: imageQuality) else { return false } let localUrl = localImageUrl(cap)