0

I'm editing an NSImage which is read from disk.The original image has exif info like the camera make, location etc. When saving the NSImage , this EXIF info is lost. I'm using the following code to write the NSImage to disk.

let cgRef = modifiedImage.cgImage(forProposedRect: nil, context: nil, hints: nil)
var newRep: NSBitmapImageRep ? = nil
if let aRef = cgRef {
    newRep = NSBitmapImageRep(cgImage: aRef)
}
newRep?.size = modifiedImage.size ?? NSSize.zero
let filepath = URL(fileURLWithPath: imageURL + ".png")
let dataToSave = newRep?.representation(using: NSBitmapImageRep.FileType.png, properties: [NSBitmapImageRep.PropertyKey.compressionFactor: 1])
do {
    try dataToSave?.write(to: filepath)
    return true
} catch {
    return false
}
    

How can i copy the exif info from the original image to the saved one?

techno
  • 6,100
  • 16
  • 86
  • 192
  • For JFIF Exif is stored in an [APP1 segment](https://en.wikipedia.org/wiki/Exif#Technical), for PNG it is stored in an [`eXIf` chunk](https://stackoverflow.com/a/24916466/4299358), for WebP it is stored in an [`EXIF` chunk](https://web.archive.org/web/20230611182651/https://developers.google.com/speed/webp/docs/riff_container#extended_file_format) - you have to pick it from the source file format and then incorporate it into the target file format - they're all different. – AmigoJack Jun 30 '23 at 13:43

0 Answers0