Kartenimport, Metadaten und Versand absichern
This commit is contained in:
1 parent
be6bd49da5
commit
427b6fa7b0
18 files changed
+643
-193
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import Foundation
|
||||
import ImageIO
|
||||
|
||||
/// Agentur-Check: what is checked before photos go to an agency server.
|
||||
public struct PreflightOptions: Codable, Hashable, Sendable {
|
||||
@@ -52,9 +53,25 @@ public struct PreflightIssue: Hashable, Identifiable, Sendable {
|
||||
}
|
||||
|
||||
public enum Preflight {
|
||||
/// Reads the actual upload files without decoding their pixels.
|
||||
static func imageSizeIssues(files: [URL], minimum: Int) -> [PreflightIssue] {
|
||||
guard minimum > 0 else { return [] }
|
||||
return files.compactMap { file in
|
||||
guard let source = CGImageSourceCreateWithURL(file as CFURL, nil),
|
||||
let info = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [CFString: Any],
|
||||
let width = info[kCGImagePropertyPixelWidth] as? Int,
|
||||
let height = info[kCGImagePropertyPixelHeight] as? Int else {
|
||||
return PreflightIssue(.error, "\(file.lastPathComponent): Bildgröße nicht lesbar")
|
||||
}
|
||||
let edge = max(width, height)
|
||||
guard edge < minimum else { return nil }
|
||||
return PreflightIssue(.error, "\(file.lastPathComponent): \(edge) px lange Kante (mindestens \(minimum) px)")
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks one photo. `openSuggestions` = codes/names of jersey suggestions still open.
|
||||
public static func check(iptc: IPTCValues, exif: [String: String], captureDate: Date?, codes: CodeReplacements,
|
||||
options: PreflightOptions, openSuggestions: [String] = []) -> [PreflightIssue] {
|
||||
options: PreflightOptions, openSuggestions: [String] = [], uploadFiles: [URL]? = nil) -> [PreflightIssue] {
|
||||
var issues: [PreflightIssue] = []
|
||||
|
||||
// 1. required fields
|
||||
@@ -134,7 +151,9 @@ public enum Preflight {
|
||||
}
|
||||
|
||||
// 7. image size
|
||||
if options.minLongEdge > 0,
|
||||
if let uploadFiles {
|
||||
issues += imageSizeIssues(files: uploadFiles, minimum: options.minLongEdge)
|
||||
} else if options.minLongEdge > 0,
|
||||
let w = exif["ImageWidth"].flatMap({ Int($0) }), let h = exif["ImageHeight"].flatMap({ Int($0) }),
|
||||
max(w, h) < options.minLongEdge {
|
||||
issues.append(PreflightIssue(.error, "Bild zu klein: \(max(w, h)) px lange Kante (mindestens \(options.minLongEdge) px)"))
|
||||
|
||||
Reference in new issue
Block a user