-
Couldn't load subscription status.
- Fork 35
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments 1 reply
-
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()?
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 1
-
Thank you! Will try to figure something out to address this usecase.
Beta Was this translation helpful? Give feedback.