• Stars
    star
    536
  • Rank 82,794 (Top 2 %)
  • Language
    Swift
  • License
    MIT License
  • Created almost 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fetch prominent colors from an image.

react-native-image-colors

Platform NPM Badge Publish size PRs Welcome

Fetch prominent colors from an image.

Example 1 Demo 1 Android Demo 1 iOS Demo 2 Android Demo 2 iOS

This module is a wrapper around the Palette class on Android, UIImageColors on iOS and node-vibrant for the web.

Installation

Expo

Requirements

  • Expo SDK 47+
yarn add react-native-image-colors
npx expo prebuild

iOS

npx expo run:ios

Android

npx expo run:android

The example is an expo app.

React Native CLI

Requirements

  • React Native v0.70.0+
  • iOS 13+
  • Expo modules must be configured

Users on < RN0.69 and older can use v1.x.x

yarn add react-native-image-colors

iOS

npx pod-install
npx react-native run-ios

Android

npx react-native run-android

Web

yarn add react-native-image-colors

Usage

import React from 'react'
import { getColors } from 'react-native-image-colors'

const useImageColors = () => {
  const [colors, setColors] = React.useState(null)

  React.useEffect(() => {
    const url = 'https://i.imgur.com/68jyjZT.jpg'

    getColors(url, {
      fallback: '#228B22',
      cache: true,
      key: url,
    }).then(setColors)
  }, [])

  return colors
}

API

ImageColors.getColors(uri: string, config?: Config): Promise<ImageColorsResult>

uri

A string which can be:

  • URL:

    https://i.imgur.com/O3XSdU7.jpg

  • Local file:

    const catImg = require('./images/cat.jpg')
  • Base64:

    const catImgBase64 = 'data:image/jpeg;base64,/9j/4Ri...'

    The mime type prefix for base64 is required (e.g. data:image/png;base64).

Config?

The config object is optional.

Property Description Type Default Supported platforms
fallback If a color property couldn't be retrieved, it will default to this hex color string string "#000000" All
cache Enables in-memory caching of the result - skip downloading the same image next time. boolean false All
key Unique key to use for the cache entry. The image URI is used as the unique key by default. You should explicitly pass a key if you enable caching and you're using a base64 string as the URI. string undefined All
headers HTTP headers to be sent along with the GET request to download the image Record<string, string> undefined iOS, Android
pixelSpacing How many pixels to skip when iterating over image pixels. Higher means better performance (note: value cannot be lower than 1). number 5 Android
quality Highest implies no downscaling and very good colors. 'lowest'
'low'
'high'
'highest'
"low" iOS, Web

ImageColorsResult

Every result object contains a respective platform key to help narrow down the type.

AndroidImageColors

Property Type
dominant string
average string
vibrant string
darkVibrant string
lightVibrant string
darkMuted string
lightMuted string
muted string
platform "android"

WebImageColors

Property Type
dominant string
vibrant string
darkVibrant string
lightVibrant string
darkMuted string
lightMuted string
muted string
platform "web"

IOSImageColors

Property Type
background string
primary string
secondary string
detail string
platform "ios"

Notes

  • There is an example app.
  • Since the implementation of each platform is different you can get different color results for each.

More Repositories

1

spotify-lite

Spotify Lite made with React Native for iOS and Android
TypeScript
382
star
2

react-native-template

Minimal template with best practices and automation scripts for improved developer experience.
TypeScript
217
star
3

reactnative-fastlane-appcenter

🚀 A fastlane step-by-step guide for signing, building and uploading new React Native apps to visual studio app center.
160
star
4

liveness-detection-react-native

Intro to Liveness Detection with React Native
TypeScript
31
star
5

react-native-revolver-view

A revolving picker view.
TypeScript
28
star
6

react-native-balloon-slider

Slider with a floating balloon animation. Works on iOS, Android and the web.
TypeScript
26
star
7

react-native-freeotp

Generate the same TOTP tokens as FreeOTP from your React Native app.
Swift
7
star
8

videomag-vibration-analysis

Textile classification through vibrations captured from video.
MATLAB
5
star
9

react-native-mqtt-example

Using a CloudMQTT instance and react_native_mqtt library
JavaScript
3
star
10

jsi-playground-cxx

Java
2
star
11

camera_experiment

TypeScript
2
star
12

osamaqarem

2
star
13

android-mvrx-basics-1

Thinking in React for Native Android Apps
Kotlin
2
star
14

android-mvrx-basics-2

Android with MvRx, Retrofit, Moshi, Requery, RxJava, Navigation, Android KTX, Kotlin Android Extensions.
Kotlin
2
star
15

android-mvp-basics

Android with Thirty-inch, Retrofit, GSON, RxJava and Requery basic examples.
Java
2
star
16

rn-navigation-experiment

Java
2
star
17

intro-to-react-slides

Internal sharing session @ Innov8tif – 11th March
JavaScript
2
star
18

nextjs-tailwind-typescript-template

NextJS + Tailwind + TypeScript
JavaScript
2
star