diff --git a/frontend/src/components/ImageUpload.tsx b/frontend/src/components/ImageUpload.tsx index fb81bf7..a94e791 100644 --- a/frontend/src/components/ImageUpload.tsx +++ b/frontend/src/components/ImageUpload.tsx @@ -2,6 +2,7 @@ import { useState, useEffect, useMemo, useCallback } from "react"; import { useDropzone } from "react-dropzone"; import { toast } from "react-hot-toast"; import axios from 'axios'; +import ColorThief from 'color-thief'; const baseStyle = { flex: 1, @@ -59,6 +60,15 @@ type FileWithPreview = { .then((response) => { // Store the returned colors in the component's state setColors(response.data.colors); + // Extract the dominant color from the uploaded image + try { + const colorThief = new ColorThief(); + const dominantColor = colorThief.getColor(dataUrls[0]); + setDominantColor(dominantColor); + } catch (error) { + toast.error("Error extracting dominant color: " + error); + console.error("Error extracting dominant color:", error); + } }) .catch((error) => { toast.error("Error extracting colors: " + error); @@ -165,3 +175,4 @@ export default ImageUpload;
))} +