Skip to content

Commit 63dd5d6

Browse files
committed
šŸ›Potential fix for resizing artifacts generated by wrong image size reporting
1 parent 0e84be6 commit 63dd5d6

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

ā€ŽSources/ChangeMenuBarColor/Commands/Abstract/Command.swiftā€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Command {
5757
return nil
5858
}
5959

60+
wallpaper.adjustSize()
6061
Log.debug("Using currently set macOS wallpaper \(path)")
6162

6263
return wallpaper

ā€ŽSources/ChangeMenuBarColor/Extensions/NSImage+Extensions.swiftā€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,13 @@ extension NSImage {
110110
// Return nil in case anything fails.
111111
return nil
112112
}
113+
114+
// Images loaded from file sometimes do not report the size correctly, see https://stackoverflow.com/questions/9264051/nsimage-size-not-real-size-with-some-pictures
115+
// This can lead to artifcats produces bby resizing operations
116+
func adjustSize() {
117+
// use the biggest sizes from all the representations https://stackoverflow.com/a/38523158/581164
118+
size = representations.reduce(size) { size, representation in
119+
return CGSize(width: max(size.width, CGFloat(representation.pixelsWide)), height: max(size.height, CGFloat(representation.pixelsHigh)))
120+
}
121+
}
113122
}

0 commit comments

Comments
Ā (0)