Skip to content

Commit

Permalink
šŸ›Potential fix for resizing artifacts generated by wrong image size rā€¦
Browse files Browse the repository at this point in the history
ā€¦eporting
  • Loading branch information
igorkulman committed Nov 7, 2022
1 parent 0e84be6 commit 63dd5d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sources/ChangeMenuBarColor/Commands/Abstract/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Command {
return nil
}

wallpaper.adjustSize()
Log.debug("Using currently set macOS wallpaper \(path)")

return wallpaper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,13 @@ extension NSImage {
// Return nil in case anything fails.
return nil
}

// 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
// This can lead to artifcats produces bby resizing operations
func adjustSize() {
// use the biggest sizes from all the representations https://stackoverflow.com/a/38523158/581164
size = representations.reduce(size) { size, representation in
return CGSize(width: max(size.width, CGFloat(representation.pixelsWide)), height: max(size.height, CGFloat(representation.pixelsHigh)))
}
}
}

0 comments on commit 63dd5d6

Please sign in to comment.