image-color-analyst 1.0.4 ā 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +38 -39
- package/examples/server.js +2 -2
- package/package.json +2 -2
- package/src/analyzer.js +3 -3
package/bin/cli.js
CHANGED
|
@@ -7,19 +7,18 @@ const require = createRequire(import.meta.url);
|
|
|
7
7
|
import { program } from 'commander';
|
|
8
8
|
import chalk from 'chalk';
|
|
9
9
|
import fs from 'fs';
|
|
10
|
-
import path from 'path';
|
|
11
10
|
|
|
12
11
|
// For local modules, still use require
|
|
13
12
|
const { analyze, getDominantColor, getColorPalette } = require('../src/index');
|
|
14
13
|
|
|
15
14
|
// Display banner
|
|
16
|
-
console.log(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
);
|
|
15
|
+
// console.log(
|
|
16
|
+
// chalk.cyan(
|
|
17
|
+
// '='.repeat(60) + '\n' +
|
|
18
|
+
// 'šØ IMAGE COLOR ANALYZER šØ\n' +
|
|
19
|
+
// '='.repeat(60)
|
|
20
|
+
// )
|
|
21
|
+
// );
|
|
23
22
|
|
|
24
23
|
program
|
|
25
24
|
.name('color-analyzer')
|
|
@@ -36,43 +35,43 @@ program
|
|
|
36
35
|
try {
|
|
37
36
|
// Check if file exists
|
|
38
37
|
if (!fs.existsSync(imagePath)) {
|
|
39
|
-
console.error(chalk.red(`Error: File not found - ${imagePath}`));
|
|
38
|
+
// console.error(chalk.red(`Error: File not found - ${imagePath}`));
|
|
40
39
|
process.exit(1);
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
console.log(chalk.blue(`š· Analyzing ${imagePath}...\n`));
|
|
42
|
+
// console.log(chalk.blue(`š· Analyzing ${imagePath}...\n`));
|
|
44
43
|
|
|
45
44
|
const result = await analyze(imagePath, {
|
|
46
45
|
topColorsCount: parseInt(options.top)
|
|
47
46
|
});
|
|
48
47
|
|
|
49
48
|
if (options.output === 'json') {
|
|
50
|
-
console.log(JSON.stringify(result, null, 2));
|
|
49
|
+
// console.log(JSON.stringify(result, null, 2));
|
|
51
50
|
} else if (options.output === 'simple') {
|
|
52
|
-
console.log(chalk.bold('šØ Dominant Color:'));
|
|
53
|
-
console.log(` ${result.dominantColor.hex} - ${result.dominantColor.name}`);
|
|
54
|
-
console.log(` Percentage: ${result.dominantColor.percentage}%\n`);
|
|
51
|
+
// console.log(chalk.bold('šØ Dominant Color:'));
|
|
52
|
+
// console.log(` ${result.dominantColor.hex} - ${result.dominantColor.name}`);
|
|
53
|
+
// console.log(` Percentage: ${result.dominantColor.percentage}%\n`);
|
|
55
54
|
|
|
56
|
-
console.log(chalk.bold('š Top Colors:'));
|
|
55
|
+
// console.log(chalk.bold('š Top Colors:'));
|
|
57
56
|
result.topColors.forEach((color, index) => {
|
|
58
|
-
console.log(` ${index + 1}. ${color.hex} - ${color.name} (${color.percentage}%)`);
|
|
57
|
+
// console.log(` ${index + 1}. ${color.hex} - ${color.name} (${color.percentage}%)`);
|
|
59
58
|
});
|
|
60
59
|
} else {
|
|
61
60
|
// Table format (default)
|
|
62
61
|
console.log(chalk.bold('š Image Information:'));
|
|
63
|
-
console.log(` Dimensions: ${result.imageInfo.width} Ć ${result.imageInfo.height}`);
|
|
64
|
-
console.log(` Format: ${result.imageInfo.format}`);
|
|
65
|
-
console.log(` Processing Time: ${result.processingTime}ms\n`);
|
|
62
|
+
// console.log(` Dimensions: ${result.imageInfo.width} Ć ${result.imageInfo.height}`);
|
|
63
|
+
// console.log(` Format: ${result.imageInfo.format}`);
|
|
64
|
+
// console.log(` Processing Time: ${result.processingTime}ms\n`);
|
|
66
65
|
|
|
67
|
-
console.log(chalk.bold('šØ Dominant Color:'));
|
|
68
|
-
console.log(chalk.bgHex(result.dominantColor.hex)(' '),
|
|
69
|
-
|
|
70
|
-
console.log(` RGB: ${result.dominantColor.rgb}`);
|
|
71
|
-
console.log(` Percentage: ${result.dominantColor.percentage}%\n`);
|
|
66
|
+
// console.log(chalk.bold('šØ Dominant Color:'));
|
|
67
|
+
// console.log(chalk.bgHex(result.dominantColor.hex)(' '),
|
|
68
|
+
// ` ${result.dominantColor.hex} - ${result.dominantColor.name}`);
|
|
69
|
+
// console.log(` RGB: ${result.dominantColor.rgb}`);
|
|
70
|
+
// console.log(` Percentage: ${result.dominantColor.percentage}%\n`);
|
|
72
71
|
|
|
73
|
-
console.log(chalk.bold('š Top Colors:'));
|
|
74
|
-
console.log(chalk.cyan(' Rank Color Name Percentage'));
|
|
75
|
-
console.log(chalk.cyan(' āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā'));
|
|
72
|
+
// console.log(chalk.bold('š Top Colors:'));
|
|
73
|
+
// console.log(chalk.cyan(' Rank Color Name Percentage'));
|
|
74
|
+
// console.log(chalk.cyan(' āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā'));
|
|
76
75
|
|
|
77
76
|
result.topColors.forEach((color, index) => {
|
|
78
77
|
const rank = (index + 1).toString().padEnd(5);
|
|
@@ -81,16 +80,16 @@ program
|
|
|
81
80
|
const name = color.name.padEnd(12);
|
|
82
81
|
const percentage = color.percentage.toFixed(2).padEnd(8);
|
|
83
82
|
|
|
84
|
-
console.log(` ${rank} ${colorBlock} ${hex} ${name} ${percentage}%`);
|
|
83
|
+
// console.log(` ${rank} ${colorBlock} ${hex} ${name} ${percentage}%`);
|
|
85
84
|
});
|
|
86
85
|
|
|
87
|
-
console.log(`\nš Total unique colors: ${result.colorStats.totalColors}`);
|
|
86
|
+
// console.log(`\nš Total unique colors: ${result.colorStats.totalColors}`);
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
// Save to file if requested
|
|
91
90
|
if (options.save) {
|
|
92
91
|
fs.writeFileSync(options.save, JSON.stringify(result, null, 2));
|
|
93
|
-
console.log(chalk.green(`\nā
Results saved to ${options.save}`));
|
|
92
|
+
// console.log(chalk.green(`\nā
Results saved to ${options.save}`));
|
|
94
93
|
}
|
|
95
94
|
|
|
96
95
|
} catch (error) {
|
|
@@ -105,12 +104,12 @@ program
|
|
|
105
104
|
.action(async (imagePath) => {
|
|
106
105
|
try {
|
|
107
106
|
const dominant = await getDominantColor(imagePath);
|
|
108
|
-
console.log(chalk.bgHex(dominant.hex)(' '),
|
|
109
|
-
|
|
110
|
-
console.log(`RGB: ${dominant.rgb}`);
|
|
111
|
-
console.log(`Percentage: ${dominant.percentage}%`);
|
|
107
|
+
// console.log(chalk.bgHex(dominant.hex)(' '),
|
|
108
|
+
// chalk.bold(` ${dominant.hex} - ${dominant.name}`));
|
|
109
|
+
// console.log(`RGB: ${dominant.rgb}`);
|
|
110
|
+
// console.log(`Percentage: ${dominant.percentage}%`);
|
|
112
111
|
} catch (error) {
|
|
113
|
-
console.error(chalk.red(`Error: ${error.message}`));
|
|
112
|
+
// console.error(chalk.red(`Error: ${error.message}`));
|
|
114
113
|
}
|
|
115
114
|
});
|
|
116
115
|
|
|
@@ -122,17 +121,17 @@ program
|
|
|
122
121
|
try {
|
|
123
122
|
const palette = await getColorPalette(imagePath, parseInt(options.colors));
|
|
124
123
|
|
|
125
|
-
console.log(chalk.bold(`šØ Color Palette (${options.colors} colors):\n`));
|
|
124
|
+
// console.log(chalk.bold(`šØ Color Palette (${options.colors} colors):\n`));
|
|
126
125
|
|
|
127
126
|
palette.forEach((color, index) => {
|
|
128
127
|
const swatch = chalk.bgHex(color.hex)(' ');
|
|
129
|
-
console.log(`${swatch} ${color.hex.padEnd(10)} ${color.name.padEnd(12)} ${color.percentage.toFixed(2)}%`);
|
|
128
|
+
// console.log(`${swatch} ${color.hex.padEnd(10)} ${color.name.padEnd(12)} ${color.percentage.toFixed(2)}%`);
|
|
130
129
|
});
|
|
131
130
|
|
|
132
131
|
// Generate CSS
|
|
133
|
-
console.log(chalk.bold('\nš
CSS Variables:'));
|
|
132
|
+
// console.log(chalk.bold('\nš
CSS Variables:'));
|
|
134
133
|
palette.forEach((color, index) => {
|
|
135
|
-
console.log(`--color-${index + 1}: ${color.hex};`);
|
|
134
|
+
// console.log(`--color-${index + 1}: ${color.hex};`);
|
|
136
135
|
});
|
|
137
136
|
|
|
138
137
|
} catch (error) {
|
package/examples/server.js
CHANGED
|
@@ -86,6 +86,6 @@ app.post('/analyze', upload.single('image'), async (req, res) => {
|
|
|
86
86
|
});
|
|
87
87
|
|
|
88
88
|
app.listen(PORT, () => {
|
|
89
|
-
console.log(`š Server running on http://localhost:${PORT}`);
|
|
90
|
-
console.log(`š Upload endpoint: POST http://localhost:${PORT}/analyze`);
|
|
89
|
+
// console.log(`š Server running on http://localhost:${PORT}`);
|
|
90
|
+
// console.log(`š Upload endpoint: POST http://localhost:${PORT}/analyze`);
|
|
91
91
|
});
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "image-color-analyst",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Analyze images to find dominant colors and color distribution",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"bin": {
|
|
8
|
-
"color-analyzer": "
|
|
8
|
+
"color-analyzer": "bin/cli.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"start": "node src/index.js",
|
package/src/analyzer.js
CHANGED
|
@@ -81,9 +81,9 @@ async function analyzeImageColors(imagePath, options = {}) {
|
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
// Add color name if requested
|
|
84
|
-
if (includeNames) {
|
|
85
|
-
|
|
86
|
-
}
|
|
84
|
+
// if (includeNames) {
|
|
85
|
+
// colorObj.name = getColorName(r, g, b);
|
|
86
|
+
// }
|
|
87
87
|
|
|
88
88
|
return colorObj;
|
|
89
89
|
});
|