File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -63,14 +63,20 @@ public extension NSImage {
6363 ///
6464 /// - parameter url: The location url to which to write the png file.
6565 func savePNGRepresentationToURL( url: URL , onlyChange: Bool = true ) throws {
66- if let png = self . PNGRepresentation {
66+ if let pngData = self . PNGRepresentation {
6767 if let originalData = try ? Data ( contentsOf: url) {
68- if onlyChange && ( png == originalData) {
68+
69+ // The beginning of PNG contains some data that may differ - a header
70+ let originalSubdata = originalData. subdata ( in: 175 ..< originalData. endIndex)
71+ let pngSubdata = pngData. subdata ( in: 175 ..< pngData. endIndex)
72+
73+
74+ if onlyChange && ( pngSubdata == originalSubdata) {
6975 return
7076 }
7177 }
7278
73- try png . write ( to: url, options: . atomicWrite)
79+ try pngData . write ( to: url, options: . atomicWrite)
7480 }
7581 }
7682
You can’t perform that action at this time.
0 commit comments