MCPcopy Create free account
hub / github.com/adobe/leonardo / getClosestColorName

Function getClosestColorName

docs/ui/src/js/predefinedColorNames.js:50–66  ·  view source on GitHub ↗
(color)

Source from the content-addressed store, hash-verified

48];
49
50function getClosestColorName(color) {
51 let diffs = [];
52 let keys = [];
53 for (const [key, value] of Object.entries(colorNames)) {
54 let colorDifference = getColorDifference(color, value);
55 if (colorDifference < 10) {
56 diffs.push(colorDifference);
57 keys.push(key);
58 }
59 }
60 if (diffs.length > 0) {
61 const minDiff = Math.min(...diffs);
62 const index = diffs.indexOf(minDiff);
63 const closestMatchingKey = keys[index];
64 return capitalizeFirstLetter(closestMatchingKey);
65 }
66}
67
68function getRandomColorName() {
69 const existingColorNames = getAllColorNames();

Callers 2

paramSetupFunction · 0.90
addColorsFromImageFunction · 0.90

Calls 2

getColorDifferenceFunction · 0.90
capitalizeFirstLetterFunction · 0.90

Tested by

no test coverage detected