Skip to content

Repository files navigation

Xcode Build

UIImageColors

iTunes style color fetcher for UIImage and NSImage. It fetches the most dominant and prominent colors.

Installation

Add the following to the dependencies of your Package.swift:

.package(url:"https://github.com/jathu/UIImageColors.git", from:"x.x.x")

Add UIImageColors to your Podfile:

pod 'UIImageColors'

Add UIImageColors to your Cartfile:

github "jathu/UIImageColors"

Manual

Copy the UIImageColors folder into your project.

For Objective-C projects copy the entire Sources folder.

Examples

iOS (Swift)
import UIImageColors
letimage=UIImage(named:"example.png")
// Synchronous
letcolors= image.getColors()
// Asynchronous(completion-handler)
image.getColors{ colors in}
// Asynchronous(async/await)
letcolors=await image.colors()
iOS (Objective-C)
@import UIImageColorsObjc;
UIImage *image = [UIImage imageNamed:@"example.png"];
// Synchronous
UIImageColors *colors = [image getColorsWithQuality:UIImageColorsScaleQualityHigh];
// Asynchronous
[image getColorsWithQuality:UIImageColorsScaleQualityHigh completion:^(UIImageColors * _Nullable colors) {
}];
macOS (Swift)
import UIImageColors
letimage=NSImage(named:"example.png")
// Synchronous
letcolors= image.getColors()
// Asynchronous(completion-handler)
image.getColors{ colors in}
// Asynchronous(async/await)
letcolors=await image.colors()
macOS (Objective-C)
@import UIImageColorsObjc;
NSImage *image = [NSImageimageNamed:@"example.png"];
// Synchronous
NSImageColors *colors = [image getColorsWithQuality:UIImageColorsScaleQualityHigh];
// Asynchronous
[image getColorsWithQuality:UIImageColorsScaleQualityHigh completion:^(NSImageColors * _Nullable colors) {
}];

Colors-object

Colors is an object that contains four different color-properties and is used as the return type.

PropertyDescription
backgroundThe most common, non-black/white color.
primaryThe most common color that is contrasting with the background.
secondaryThe second most common color that is contrasting with the background. Also must distinguish itself from the primary color.
detailThe third most common color that is contrasting with the background. Also must distinguish itself from the primary and secondary color.

In Swift Colors is a struct and an extension of UIImage/NSImage; in Objective-C there is a UIImageColors/NSImageColors class which is a concrete subclass of NSObject.

ScaleQuality-enum

ScaleQuality is an enum with four different qualities. The qualities refer to how much the original image is scaled down. Higher qualities will give better results at the cost of performance.

ValueQuality
low50 pixel
medium100 pixel
high250 pixel
fullno scaling
custom (Swift only)given value

All methods provide a quality parameter (which is set to .high by default in Swift).

letcolors= image.getColors(quality:.low)letasyncColors=await image.colors(quality:.custom(10))
image.getColors(quality:.full){ colors in /*...*/ }
UIImageColors *colors = [image getColorsWithQuality:UIImageColorsScaleQualityLow];
[image getColorsWithQuality:UIImageColorsScaleQualityFull completion:^(NSImageColors * _Nullable colors) { /*...*/ }];

License

The license is provided in the project folder. This is based on Panic's OS X ColorArt.


June 2015 - Toronto

About

Fetches the most dominant and prominent colors from an image.

Resources

Stars

41 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages