Skip to content

Commit

Permalink
Made the package much more lightweight using jimp
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinandanwadwa committed Dec 25, 2022
1 parent cafa59f commit b9f37a8
Show file tree
Hide file tree
Showing 3 changed files with 1,343 additions and 114 deletions.
23 changes: 17 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import axios from 'axios';
import Jimp from 'jimp';

async function extractSingleColor(imageURI) {
const response = await axios.post('https://image-color-extractor-server-production.up.railway.app/api/getsinglecolor', {
imageURI: imageURI
});
return response.data;
const extractSingleColor = async (imageURI) => {
let colorArrays = [];
await Jimp.read(imageURI)
.then(image => {
const { width, height } = image.bitmap;

for(let i=0; i<width; i++) {
for(let j=0; j<height; j++) {
colorArrays.push(image.getPixelColor(i, j));
}
}
});
let x = Math.floor((Math.random() * (colorArrays.length-1)) + 1);
const hex = colorArrays[x];
return Jimp.intToRGBA(hex);
}



export default extractSingleColor;
Loading

0 comments on commit b9f37a8

Please sign in to comment.