Skip to content

mhmiles/SwiftColorSampler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftColorSampler

Carthage Compatible

SwiftColorSampler is a UIImage extension for sampling prominent colors from an image. I built this to mimic the cover art color palette generation in iTunes 11. See this StackOverflow question for more details.

Installation

Carthage

SwiftColorSampler is available to install with Carthage. To integrate SwiftColorSampler into your Xcode project using Carthage, specify it in your Cartfile:

github "mhmiles/SwiftColorSampler" ~> 0.1.0

Manually

If you prefer not to use Carthage, you can integrate SwiftColorSampler into your project manually.

Embedded Framework

  • Open up Terminal, cd into your top-level project directory, and run the following command "if" your project is not initialized as a git repository:
$ git init
  • Add SwiftColorSampler as a git submodule by running the following command:
$ git submodule add https://github.com/mhmiles/SwiftColorSampler.git
  • Open the new SwiftColorSampler folder, and drag the SwiftColorSampler.xcodeproj into the Project Navigator of your application's Xcode project.

    It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.

  • Select the SwiftColorSampler.xcodeproj in the Project Navigator and verify the deployment target matches that of your application target.

  • Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.

  • In the tab bar at the top of that window, open the "General" panel.

  • Click on the + button under the "Embedded Binaries" section.

  • Select the SwiftColorSampler.framework.

  • And that's it!

The SwiftColorSampler.framework is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.

Usage

UIImage.sampleColors(count: Int, colorDepth: Int = 4)

Reduces the full color palette an image to a reduce palette of size count. colorDepth is an optional parameter that affects the precision of the quantization with a maximum of 8 and a default of 4. A higher colorDepth increases precision at the cost of performance. Values nearer to 8 are only recommended for images with a very low color count and where high precision is desired.

UIImage.sampleColors(count: Int, rect: CGRect, colorDepth: Int = 4)

Applies sampleColors to a subregion of an image bounded by rect.

Contributing

All pull requests will be considered. Feel free to contact me with any questions or suggestions.

Special Thanks

License

SwiftColorSampler is released under the MIT license.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published