-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcolor.js
48 lines (40 loc) · 1.27 KB
/
color.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const scraper = require("images-scraper");
const download = require("image-downloader");
const merge = require("merge-img");
const colorthief = require("colorthief");
const species = require("./catalogs/species.json")
let LIMIT = 2;
const google = new scraper({
puppeteer:{
headless: true
}
});
async function searchAnalize(specie,query){
const images = await google.scrape(query, 3);
//console.log(images);
const downloads = await Promise.all( images.map( async image => {
let date = new Date();
let filename = date.getTime();
let options = {
url: image['url'],
dest: `./images/${filename}.jpg`
};
return await download.image(options);
}) );
//console.log(downloads);
let img = await merge(downloads.map( download => download.filename) )
let path =`./collage/${specie}.png`;
img.write(path , async () => {
const color = await colorthief.getColor(path);
console.log(color);
});
}
function init(){
console.log(`Species : ${species.length}`)
for(let index = 0; index< LIMIT; index++){
searchAnalize(species[index],
`"${species[index]}" filetype:jpg -blue -white imagesize:medium`);
//console.log(species[index]);
}
}
init();