Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Please consider adding a function returning and rgb array. [0..255, 0..255, 0..255] #263

marcelpi started this conversation in Ideas
Discussion options

Hi Dan,

I'm using your library in one of my projects and it's great tbh. Thanks for your work.
I'm working with rgb array tuples and am constantly converting between arrays and culori's objects.

It would be really nice if you could add a function that does that automatically.
Maybe something like formatRgbArray(color) returning a [0..255, 0..255, 0..255] array.
And formatRgbArrayNormalized(color) returning a [0..1, 0..1, 0..1] array.

Anyway, please consider it and thanks again.

You must be logged in to vote

Replies: 2 comments 1 reply

Comment options

Hi Marcel, thanks for the suggestion (and the kind words!). Since there’s a degree of customization involved in the output (clamping to gamut, rounding/number of decimals, etc.), I’m not sure the library can abstract away things significantly.

We could add a method to serialize a color object as an array of ordered coordinates that works across color spaces, such as:

import { formatArray, round } from 'culori';
formatArray(color).map(round(4)) => // [0..1, 0..1, 0..1] with four decimals
formatArray(color).map(v => Math.round(v * 255)) // [0..255, 0..255, 0..255]

But I’m not really sure if that’s any easier than doing:

[color.r, color.g, color.b].map(...)

Is there a wide use for one specific kind of array representation we could use as rationale for implementing a formatRgbArray()?

You must be logged in to vote
0 replies
Comment options

I'm interpolating colors across a 3d space and the format I'm using for the colors is an RGB array. I found myself constantly having to switch formats between strings, arrays and objects and this conversion happened quite often.

In any case, I defined my own function to handle this, but it would've been nice to have it as part of culori. I needed it to work on all color objects, not just RGB colors.

function formatRgbArray(color: any): RGB {
 const rgbString = formatRgb(color) as string | undefined
 if (!rgbString) return [0, 0, 0]
 const match = rgbString.match(/\d+(\.\d+)?/g)?.slice(0,3).map(Number)
 return match as RGB
}

If you think it's not worth the trouble, please skip this request.

Thank again for your work, culori overall is an awesome library. I'm from Cluj as well and am proud it was developed here, congrats.

You must be logged in to vote
1 reply
Comment options

Thank you! Will try to figure something out to address this usecase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /