Open ngothikieuvuong opened 7 years ago
Hi @vuongngolg !
I see a few issues:
if (err) throw err;
is not throwing because the argument is called error
When using a buffer, you need to specify its mime type:
getColors(buffer, 'image/gif').then(colors => {
// `colors` is an array of color objects
})
But you don't have to use a buffer if you don't want to specify the mimetype. You can just pass a fully-qualified filename:
const path = require('path')
const getColors = require('get-image-colors')
getColors(path.join(__dirname, 'double-rainbow.png')).then(colors => {
// `colors` is an array of color objects
})
See https://github.com/zeke/get-image-colors#usage for more info. Hope this helps.
Thanks @zeke
I've tried 2 ways as following:
var color;
var path = require('path');
return color = getColors(path.join(__dirname, '/../resources/uploadData/', '1.png')).then(color => {
console.log(color); // Log: [Color {_rgb: [239, 238, 237, 1]} ,... ]
});
var path = require('path');
getColors(path.join(__dirname, '/../resources/uploadData/', '1.png')).then(color => {
console.log("running"); // Log nothing, it doesn't run into this block codes
});
The first way can run into step and log color, but the second way cannot. I don't know why. Could you help me to explain? Anyway, I am applying the first way. Thanks
Try this:
var path = require('path')
var file = path.join(__dirname, '/../resources/uploadData/', '1.png')
console.log(file)
// does that look like the right file path?
getColors(file)
.catch(err => {
throw err
})
.then(color => {
console.log(colors)
})
Thanks, I tried exactly the same, but it doesn't work, see comment in line
var path = require('path') var file = path.join(__dirname, '/../resources/uploadData/', '1.png')
console.log(file) // does that look like the right file path? --> Yes, it logs the right path, and the file is existing on this path.
getColors(file) .catch(err => { throw err //does not log error }) .then(color => { console.log(colors) // does not log anything })
can you drag and drop your png file here?
Hi, I have an issue when using getColors, it log error: "Error: Invalid File Type" I am writing the automation scripts in synchronous style with Chimp. My scripts is as below:
Please help me where I am wrong? Thanks!