npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-jsi-color

v0.1.2

Published

Color functions that are implemented with JSI, including getting the color of a pixel in an image.

Downloads

4

Readme

JSI Color

React native library that provides functions for colors, such as distance using the CIEDE2000 algorithm and getting the color of a pixel in an image.

Installation

yarn add react-native-jsi-color
npx pod-install

Example

An example app using the library and showing its usage can be found in the example folder.

Usage

Everything is implemented in TypeScript and extensive documentation can be found in the comments.

Getting the color of a pixel

If you need to get the color of a pixel in an image, you can use the getPixelColor function. It takes the filepath to the image as the first parameter and the coordinates of the pixel as the second parameter and third paramter. It returns the color in "rgb(r, g, b)" format.

Make sure that the image is does not contain file:// before its path. If it does, the function will not be able to find the image, leading to unpredictable behavior.

Also, if you are trying to implement functionality that if a user taps on an image (with gesture handler) and it shows the pixel color, you need to watch out for the resizeMode, since the image might be cropped.

Optionally, you can pass the image view dimensions and the actual image dimensions. Then, the function will return the color of the pixel in the image, taking these into account.

import { getPixelColor } from 'react-native-jsi-color';

const color = getPixelColor('/path/to/image', x, y);
console.log(color);

Getting the distance between two colors

This functionality is implemented by the computeColorDistance function. It takes two colors as parameters and returns the distance between them. The colors are required to be in the format "rgb(r, g, b)". The distance is returned as a number. The CIEDE2000 algorithm is used to compute the distance.

import { computeColorDistance } from 'react-native-jsi-color';

const distance = computeColorDistance('rgb(255, 0, 0)', 'rgb(0, 0, 255)');
console.log(distance);

Getting the color name of an rgb

If you need to get the color name of an rgb, you can use the getClosestColorName function. It takes the color in "rgb(r, g, b)" format and returns the color name of the closest color (formally, the color with the smallest distance, using computeColorDistance, to the given color).

By default, the function will look through all named HTML colors and return the closest color. However, you are also able to pass a list of your own colors as an optional parameter. This is useful if you have predefined colors that you want to use. These should be passed as an array of objects containing the name and the color in "rgb(r, g, b)" format.

Optionally, you can also set the onlyClosest option to false, which will make the function return a list of all colors, sorted by their distance to the given color.

import { getClosestColorName } from 'react-native-jsi-color';

const colorName = getClosestColorName('rgb(255, 0, 0)', {
  onlyClosest: false,
  colors: [
    {
      name: 'red',
      color: 'rgb(255, 0, 0)',
    },
    {
      name: 'green',
      color: 'rgb(0, 255, 0)',
    },
    {
      name: 'blue',
      color: 'rgb(0, 0, 255)',
    },
  ],
});
console.log(colorName);

License

MIT