NSImageColors
May 18, 2017 ยท View on GitHub
iTunes style color fetcher for NSImage. This is based on Panic's OS X ColorArt for iOS Swift.
In other words, it fetches the most dominant and prominent colors.

Example
Asynchronous example:
let image = NSImage(named: "yeezus.png")
image.getColors { colors in
backgroundView.backgroundColor = colors.background
mainLabel.textColor = colors.primary
secondaryLabel.textColor = colors.secondary
detailLabel.textColor = colors.detail
}
Synchronous example:
let colors = NSImage(named: "yeezus.png").colors
backgroundView.backgroundColor = colors.background
mainLabel.textColor = colors.primary
secondaryLabel.textColor = colors.secondary
detailLabel.textColor = colors.detail
NSImage Methods
getColors() -> NSImageColors
Returns a NSImageColors object. The sample image is rescaled to a width of 250px and the aspect ratio height. This blocks the main thread.
getColors(scaleDownSize: CGSize) -> NSImageColors
Returns a NSImageColors object with a custom image rescale. Use smaller sizes for better performance at the cost of quality colors. Use larger sizes for better color sampling and quality at the cost of performance. This blocks the main thread.
getColors(completionHandler: (NSImageColors) -> Void) -> Void
Passes a NSImageColors object into the closure. The sample image is rescaled to a width of 250px and the aspect ratio height. This runs on the background thread.
getColors(scaleDownSize: CGSize, completionHandler: (NSImageColors) -> Void) -> Void
Passes a NSImageColors object into the closure, with a custom image rescale. Use smaller sizes for better performance at the cost of quality colors. Use larger sizes for better color sampling and quality at the cost of performance. This runs on the background thread.
NSImageColors
NSImageColors is struct that contains four different NSColors.
var background
var primary
var secondary
var detail
License
The license is provided in the project folder. Please also refer to Panic's original license.
June 2015 - Toronto