Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jathu/uiimagecolors
Fetches the most dominant and prominent colors from an image.
https://github.com/jathu/uiimagecolors
ios itunes uicolor uiimage
Last synced: about 2 months ago
JSON representation
Fetches the most dominant and prominent colors from an image.
- Host: GitHub
- URL: https://github.com/jathu/uiimagecolors
- Owner: jathu
- License: mit
- Archived: true
- Created: 2015-06-19T08:00:52.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-12-14T14:24:39.000Z (almost 3 years ago)
- Last Synced: 2024-09-26T03:42:21.794Z (about 2 months ago)
- Topics: ios, itunes, uicolor, uiimage
- Language: Swift
- Homepage:
- Size: 49.7 MB
- Stars: 3,241
- Watchers: 43
- Forks: 240
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![Swift](https://img.shields.io/badge/Swift-5.0-orange.svg)
![platform: iOS, tvOS and macOS](https://img.shields.io/badge/platform-iOS%20%7C%20tvOS%20%7C%20macOS-lightgrey.svg)# UIImageColors
iTunes style color fetcher for `UIImage` and `NSImage`. It fetches the most dominant and prominent colors.
![preview](preview.png)
## Installation
### Manual
Copy [UIImageColors.swift](UIImageColors/Sources/UIImageColors.swift) into your project.
### [Cocoapods](https://cocoapods.org)
Add UIImageColors to your [`Podfile`](https://cocoapods.org/pods/UIImageColors):
```
pod 'UIImageColors'
```### [Carthage](https://github.com/Carthage/Carthage)
Add UIImageColors to your `Cartfile`:
```
github "jathu/UIImageColors"
```## Example
Asynchronous example:
```swift
let image = UIImage(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:
```swift
let colors = UIImage(named: "yeezus.png").getColors()backgroundView.backgroundColor = colors.background
mainLabel.textColor = colors.primary
secondaryLabel.textColor = colors.secondary
detailLabel.textColor = colors.detail
```## Image Methods
```swift
getColors() -> UIImageColors?
getColors(quality: ImageColorsQuality) -> UIImageColors?
getColors(_ completion: (UIImageColors?) -> Void) -> Void
getColors(quality: UIImageColorsQuality, _ completion: (UIImageColors?) -> Void) -> Void
```## UIImageColors Objects
`UIImageColors` is struct that contains four different `UIColor` (or `NSColor` on macOS) variables.
```swift
public struct UIImageColors {
public var background: UIColor!
public var primary: UIColor!
public var secondary: UIColor!
public var detail: UIColor!
}
````UIImageColorsQuality` is a enum with four different qualities. The qualities refer to how much the original image is scaled down. `Lowest` implies smaller size and faster performance at the cost of quality colors. `High` implies larger size with slower performance with good colors. `Highest` implies no downscaling and very good colors, but it is very slow.
The default is set to `high`.
```swift
public enum UIImageColorsQuality: CGFloat {
case lowest = 50 // 50px
case low = 100 // 100px
case high = 250 // 250px
case highest = 0 // No scale
}
```## License
The [license](https://github.com/jathu/UIImageColors/blob/master/LICENSE) is provided in the project folder. This is based on Panic's [OS X ColorArt](https://github.com/panicinc/ColorArt/#license).
------
June 2015 - Toronto