Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/anubra266/emoji-palette

🏇 Get color palettes from emojis
https://github.com/anubra266/emoji-palette

color color-palette emoji javascript

Last synced: about 2 months ago
JSON representation

🏇 Get color palettes from emojis

Awesome Lists containing this project

README

        




🏇


emoji-palette











npm package


npm  downloads


NPM

GitHub Repo stars




Get color palettes for emojis.










npm i emoji-palette











## Install

```bash
npm i --save emoji-palette
#or
yarn add emoji-palette
#or
pnpm add emoji-palette
```

CleanShot 2023-01-24 at 14 50 44@2x
CleanShot 2023-01-24 at 14 50 29@2x
CleanShot 2023-01-24 at 14 50 15@2x

## About

Came across some tweets by [Shayan](https://twitter.com/imsh4yy?s=21&t=ETlRoiFLQAAJRfdOAWUkEg) about LogSnag. He put up this amazing UI where gradients were formed based on a selected emoji. I scourged the comments for any hint on how he achieved this, found none, so I decided to create mine.

## How does it work

When you pass in an emoji as a string, it gets drawn unto an html canvas. This allows us to get the image back as a base64 encoded image.
From this, we're able to move through the pixels in the image to get all the relevant colors.

## Usage

```ts
// import generatePalette
import { generatePalette } from "emoji-palette";

// Pass your emoji to this method
const palette = generatePalette("👍");
```

The method returns an array of colors, in their order of luminance.
So you can get the median color in the palette if you need one.
```ts
const dominantColor = palette[Math.floor(palette.length / 2)];
```

Colors are returned as `rgb` strings.

You can see a live demo [here](https://anubra266.github.io/emoji-palette/)
Codesandbox example [here](https://codesandbox.io/p/sandbox/confident-silence-l6cbju)

## Sponsors ✨

Thanks goes to these wonderful people