A React Native node module that grabs the dominant color or a representative color palette from an image uri.
An adapted version of Sven Woltmann's fast color-thief-java and Kazuki Ohara's ColorThiefSwift from Lokesh Dhakar's original javascript project color-thief
$ npm install git://github.com/6DegreeLabs/react-native-color-thief.git --save
//TODO $ npm install react-native-color-thief --save
$ react-native link react-native-color-thief
Requirements
- Xcode 10.2
- Swift 5
- iOS 9
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-color-thief
and addRNColorThief.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNColorThief.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.RNColorThief.RNColorThiefPackage;
to the imports at the top of the file - Add
new RNColorThiefPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-color-thief' project(':react-native-color-thief').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-color-thief/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-color-thief')
Both getColor
and getPalette
return a Promise
.
import RNColorThief from 'react-native-color-thief';
// get array of color objects [{ r, g, b }]
RNColorThief.getPalette(imageUri, colorCount, quality, includeWhite).then((palette) => {
console.log('palette', palette);
}).catch((error) => {
console.log('error', error);
});
// get dominant color object { r, g, b }
RNColorThief.getColor(imageUri, quality, includeWhite).then((color) => {
console.log('color', color);
}).catch((error) => {
console.log('error', error);
});
This library is used by following apps. Please send a pull request if you are also using the library.
- (iOS) If you aren't currently using swift in your project, you may need to add a
dummy.swift
file with a bridging header in order to successfully build.