Skip to content

Commit

Permalink
Strip GPS metadata from images
Browse files Browse the repository at this point in the history
  • Loading branch information
starkdmi committed Apr 7, 2024
1 parent a76e308 commit 3a1f5e8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Sources/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ public struct ImageTool {
try saveImage(images,
at: destination,
overwrite: overwrite,
skipGPSMetadata: skipMetadata,
settings: settings,
orientation: orientation,
isHDR: isHDR,
Expand Down Expand Up @@ -435,6 +436,7 @@ public struct ImageTool {
_ frames: [ImageFrame],
at url: URL,
overwrite: Bool = false,
skipGPSMetadata: Bool = false,
settings: ImageSettings,
orientation: CGImagePropertyOrientation? = nil,
isHDR: Bool? = nil,
Expand Down Expand Up @@ -465,6 +467,10 @@ public struct ImageTool {
switch imageFormat {
case .heif, .heif10, nil:
let ciContext = CIContext()
var metadata = metadata
if skipGPSMetadata {
metadata?[kCGImagePropertyGPSDictionary] = nil
}

// Get image
let ciImage: CIImage
Expand Down Expand Up @@ -551,6 +557,11 @@ public struct ImageTool {
kCGImageDestinationEmbedThumbnail: embedThumbnail
]

// Exclude GPS
if skipGPSMetadata {
imageOptions[kCGImageMetadataShouldExcludeGPS] = kCFBooleanTrue!
}

// Adjust colors for sharing
if settings.optimizeColorForSharing {
imageOptions[kCGImageDestinationOptimizeColorForSharing] = optimizeColors
Expand Down Expand Up @@ -600,8 +611,8 @@ public struct ImageTool {
}

// IPTC
if let apple = metadata[kCGImagePropertyIPTCDictionary] {
imageOptions[kCGImagePropertyIPTCDictionary] = apple
if let iptc = metadata[kCGImagePropertyIPTCDictionary] {
imageOptions[kCGImagePropertyIPTCDictionary] = iptc
}
}

Expand Down

0 comments on commit 3a1f5e8

Please sign in to comment.