Fetches the most dominant and prominent colors from an image.

Overview

Swift platform: iOS, tvOS and macOS

UIImageColors

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

preview

Installation

Manual

Copy UIImageColors.swift into your project.

Cocoapods

Add UIImageColors to your Podfile:

pod 'UIImageColors'

Carthage

Add UIImageColors to your Cartfile:

github "jathu/UIImageColors"

Example

Asynchronous example:

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:

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

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.

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.

public enum UIImageColorsQuality: CGFloat {
    case lowest = 50 // 50px
    case low = 100 // 100px
    case high = 250 // 250px
    case highest = 0 // No scale
}

License

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


June 2015 - Toronto

Comments
  • 3.0.0 (entirely rebuild)

    3.0.0 (entirely rebuild)

    Hey, I've rebuild the entire repository and would also maintain it in the future if you want.

    What I did:

    • fixed memory leak (UIGraphicsGetImageFromCurrentImageContext() can create one)
    • fixed macOS image scaling (it doesn't work at all right now) and handled different pixel-formats (RGBA order can vary)
    • used modern Swift collections for better performance
    • UIImageColors -> UIImage.Colors/NSImage.Colors (old still available through typealias, but deprecated)
    • restructured everything and grouped code logically in internal structs
    • the library is now a Swift Package instead of an Xcode project
    • added async/await API
    • added Objective-C API (second target for SPM and second podspec file for CocoaPods)
    • added code-documentation
    • rebuild the example project and added examples for iOS-Objective-C, macOS-Swift and macOS-Objective-C
    • added Unit-tests for all supported platforms
    • added GitHub-Actions CI workflow for all supported platforms
    • updated the README (including new screenshots)

    Please let me know if you don't want to merge it, otherwise I'll contribute it on my own!

    opened by FelixHerrmann 11
  • Add support for macOS

    Add support for macOS

    This adds support for macOS. It includes a Mac framework and example project. Both are prefixed with NS instead of UI. Code is shared between both platforms though.

    To make the project feel at home on both platforms I've taken the liberty to rename the UIImageColors struct and UIImageColorsQuality enum to ImageColors and ImageColorsQuality respectively. I've left UIImageColors intact in every other area to not mess with the branding of the repo.

    I've updated the version to 2.1.0 as this alters the API just a bit: ImageColors is returned as an optional to take into account that the process could fail. To finalize a release a tag should be added to the repo.

    preview-macos

    opened by boyvanamstel 11
  • Swift 3 syntax update

    Swift 3 syntax update

    Updated all code to Swift 3 syntax, tested the packaged playground and everything works as expected.

    Note: I've never used podspec files so that may require more work.

    Resolves #35

    opened by MichaelKraft 10
  • Fix issue of considering semi-transparent pixels

    Fix issue of considering semi-transparent pixels

    • Using cgImage data provider to access pixel data now. Code is significantly reduced for that portion
    • Now only pixels that have have a max transparency of 50% are considered
    • We now consider the whole image for the background color. We used to just consider a small margin before. This produces better results overall
    • New preview for better examples
    • Update version to 1.3.0

    Fixes issues: #20 and #47

    opened by jathu 3
  • Update `getColors()` in synchronous and asynchronous way.

    Update `getColors()` in synchronous and asynchronous way.

    • Add getColors(scaleDownSize: CGSize = CGSize.zero) -> UIImageColors (in main thread)
    • Update getColors(scaleDownSize: CGSize = CGSize.zero, completionHandler: (UIImageColors) -> Void) (in background thread)
    • Add default value for scaleDownSize parameter, remove duplicated method
    • Add documentation for public methods
    • Update playground accordingly.
    opened by honghaoz 3
  • getColors now visible to Objective-C code

    getColors now visible to Objective-C code

    getColors extension uses return type not visible to Objective-C project [XCode 9] so i added another version that returns an array of UIColors (it could be improved returning a NSDictionary with meaningful keys).

    opened by esses77 2
  • Fixed issues with compiling under Swift 2.3

    Fixed issues with compiling under Swift 2.3

    UIImage.CGImage and UIGraphicsGetImageFromCurrentImageContext() are now optional in Swift 2.3, so this change fixes this issue in a way that is compatible with Swift 2.2 as well.

    opened by thomasrzhao 2
  • Update Package.swift for Xcode 11 support

    Update Package.swift for Xcode 11 support

    The motivation for this change was to be able to integrate your library with a project I'm working on using Xcode 11's SPM functionality. It doesn't work with the current Package.swift, so I've added a target and library product that allows it to work for both iOS and macOS projects.

    I also added .swiftpm to the .gitignore, which is generated by Xcode when you open a Package.swift file with it but only contains user-specific data.

    opened by interstateone 1
  • UIImageColors struct now has public member-wise initializer.

    UIImageColors struct now has public member-wise initializer.

    By default, the member-wise initializer for public structs is private. If we include an explicit public init, then we can create UIImageColor structs in other modules.

    For example, here is an extension to make the UIImageColors struct cacheable with Haneke: https://gist.github.com/raphaeltraviss/fa620780eacc8d57f2d75424b1b796b8

    opened by raphaeltraviss 1
  • 2x Performance Improvement

    2x Performance Improvement

    I achieved a ~2x performance improvement by removing the UIColor overhead. We now encode a color within a single double. For example, a color with RGB (255,17,112) would be represented as 25517112. We then parse out the individual components with modular arithmetic and compute our color functions on these components.

    Other changes:

    • Introduce UIImageColorsQuality enum instead of asking user to provide scale down size
    • Change the Playground example project to an iOS app example (check it out on your iPhone, it's beautiful)
    • Change album art example to paintings
    • Other minor Swift 4 changes

    As this is a big change to the library, I am incrementing the version to 2.0.0. I have tested this version on my own projects and it works well. However, due to how experimental this is, I won't be merging this PR until enough people test it.

    You can test this on the branch performance-improvement. If you test this and it works well, please give a thumbs up else provide feedback.

    Thanks ✌️

    preview

    opened by jathu 1
  • Use PlaygroundSupport instead of XCPlayground in UIImageColorsPlayground

    Use PlaygroundSupport instead of XCPlayground in UIImageColorsPlayground

    Important PlaygroundSupport behavior was previously defined in the XCPlayground module, which is deprecated in Xcode 7.

    https://developer.apple.com/reference/playgroundsupport

    opened by nasakinmaxim 1
Releases(2.2.0)
Owner
null
ColorKit makes it easy to find the dominant colors of an image

ColorKit ColorKit is your companion to work with colors on iOS. Features Installation Sample Project Contributing License Features Dominant Colors Col

Boris Emorine 570 Jan 5, 2023
Read colors from Xcode assets file.

XcodePalette Read colors from Xcode assets file. How to Use Download the XcodePalette.Executable.zip of the latest release. Extract the XcodePalette U

iMoeNya 0 Nov 12, 2021
The repository for a command line / build pipeline tool for generating colors from a human-readable text file that designers can also use.

ColorPaletteGenerator ColorPaletteGenerator is a tool that takes a human-readable input file describing a color palette, and generates the associated

horseshoe7 0 Dec 7, 2021
Terminal Colors for Swift

Terminal string styling for Swift Colors is a clean and focused solution for string styling in Swift. Usage import Colors print(Colors.blue("Blue str

Paulo Tanaka 94 Sep 9, 2022
An Xcode plugin to improve dealing with colors in your project

Crayons is an Xcode7 plugin with various features that improve working with colors in your projects ##Code palettes (iOS only) You can share palettes

Fabio Ritrovato 477 Sep 23, 2022
CameraEngine: The most advanced Camera framework in Swift

CameraEngine THIS REPOSITORY REFACTORED FROM ( https://github.com/remirobert/Cam

Mertcan Bulut 0 Jan 3, 2022
Twitter Image Pipeline is a robust and performant image loading and caching framework for iOS clients

Twitter Image Pipeline (a.k.a. TIP) Background The Twitter Image Pipeline is a streamlined framework for fetching and storing images in an application

Twitter 1.8k Dec 17, 2022
📷 A composable image editor using Core Image and Metal.

Brightroom - Composable image editor - building your own UI Classic Image Editor PhotosCrop Face detection Masking component ?? v2.0.0-alpha now open!

Muukii 2.8k Jan 3, 2023
An image download extension of the image view written in Swift for iOS, tvOS and macOS.

Moa, an image downloader written in Swift for iOS, tvOS and macOS Moa is an image download library written in Swift. It allows to download and show an

Evgenii Neumerzhitckii 330 Sep 9, 2022
📷 A composable image editor using Core Image and Metal.

Brightroom - Composable image editor - building your own UI Classic Image Editor PhotosCrop Face detection Masking component ?? v2.0.0-alpha now open!

Muukii 2.8k Jan 2, 2023
AsyncImage before iOS 15. Lightweight, pure SwiftUI Image view, that displays an image downloaded from URL, with auxiliary views and local cache.

URLImage URLImage is a SwiftUI view that displays an image downloaded from provided URL. URLImage manages downloading remote image and caching it loca

Dmytro Anokhin 1k Jan 4, 2023
AYImageKit is a Swift Library for Async Image Downloading, Show Name's Initials and Can View image in Separate Screen.

AYImageKit AYImageKit is a Swift Library for Async Image Downloading. Features Async Image Downloading. Can Show Text Initials. Can have Custom Styles

Adnan Yousaf 11 Jan 10, 2022
A complete Mac App: drag an image file to the top section and the bottom section will show you the text of any QRCodes in the image.

QRDecode A complete Mac App: drag an image file to the top section and the bottom section will show you the text of any QRCodes in the image. QRDecode

David Phillip Oster 2 Oct 28, 2022
An instagram-like image editor that can apply preset filters passed to it and customized editings to a binded image.

CZImageEditor CZImageEditor is an instagram-like image editor with clean and intuitive UI. It is pure swift and can apply preset filters and customize

null 8 Dec 16, 2022
Convert the image to hexadecimal to send the image to e-paper

ConvertImageToHex Convert the image to hexadecimal to send the image to e-paper Conversion Order // 0. hex로 변환할 이미지 var image = UIImage(named: "sample

Hankyeol Park 0 Feb 26, 2022
Image-cropper - Image cropper for iOS

Image-cropper Example To run the example project, clone the repo, and run pod in

Song Vuthy 0 Jan 6, 2022
An extremely high-performance, lightweight, and energy-efficient pure Swift async web image loader with memory and disk caching for iOS and  Watch.

KFSwiftImageLoader KFSwiftImageLoader is an extremely high-performance, lightweight, and energy-efficient pure Swift async web image loader with memor

Kiavash Faisali 343 Oct 29, 2022
FMPhotoPicker is a modern, simple and zero-dependency photo picker with an elegant and customizable image editor

FMPhotoPicker is a modern, simple and zero-dependency photo picker with an elegant and customizable image editor Quick demo Batch select/deselect Smoo

Cong Nguyen 648 Dec 27, 2022
✂️ Detect and crop faces, barcodes and texts in image with iOS 11 Vision api.

ImageDetect ImageDetect is a library developed on Swift. With ImageDetect you can easily detect and crop faces, texts or barcodes in your image with i

Arthur Sahakyan 299 Dec 17, 2022