@somesoap/react-native-image-palette
Version:
Get average color or a colors palette from an image or the image segments
33 lines (32 loc) • 1.49 kB
JavaScript
import { NativeModules, Platform } from 'react-native';
import { resolveImageSource } from './utils';
export * from './types';
const LINKING_ERROR = `The package 'react-native-image-palette' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
ios: "- You have run 'pod install'\n",
default: ''
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
// @ts-expect-error
const isTurboModuleEnabled = global.__turboModuleProxy != null;
const ImagePaletteModule = isTurboModuleEnabled ? require('./NativeImagePalette').default : NativeModules.ImagePalette;
const ImagePalette = ImagePaletteModule ?? new Proxy({}, {
get() {
throw new Error(LINKING_ERROR);
}
});
export const getAverageColor = async (uri, config = {}) => {
const resolvedSrc = resolveImageSource(uri);
return ImagePalette.getAverageColor(resolvedSrc, config);
};
export const getPalette = async (uri, config = {}) => {
const resolvedSrc = resolveImageSource(uri);
return ImagePalette.getPalette(resolvedSrc, config);
};
export const getSegmentsAverageColor = async (uri, segments, config = {}) => {
const resolvedSrc = resolveImageSource(uri);
return ImagePalette.getSegmentsAverageColor(resolvedSrc, segments, config);
};
export const getSegmentsPalette = async (uri, segments, config = {}) => {
const resolvedSrc = resolveImageSource(uri);
return ImagePalette.getSegmentsPalette(resolvedSrc, segments, config);
};
//# sourceMappingURL=index.js.map