-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made the package much more lightweight using jimp
- Loading branch information
1 parent
cafa59f
commit b9f37a8
Showing
3 changed files
with
1,343 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.