-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
48 lines (39 loc) · 1.96 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alpha</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- latest script cdn version -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/color-thief/2.4.0/color-thief.min.js" integrity="sha512-r2yd2GP87iHAsf2K+ARvu01VtR7Bs04la0geDLbFlB/38AruUbA5qfmtXwXx6FZBQGJRogiPtEqtfk/fnQfaYA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<div class="img-container">
<img id="myImage" src="photo-1531343983535-681659059ec1.avif" alt="Image" type="image/avif" style="height: 400px; width: 400px;">
</div>
<span id="image1">Dominant Color 1</span>
<span id="image2">Dominant Color 2</span>
<span id="image3">Dominant Color 3</span>
<script>
// Get reference to the image element
const image1 = document.getElementById('image1');
const image2 = document.getElementById('image2');
const image3 = document.getElementById('image3');
const image = document.getElementById('myImage');
// Create a new Color Thief instance
const colorThief = new ColorThief();
// Listen for the 'load' event of the image
image.onload = function() {
// Use Color Thief to get the dominant color from the image
const dominantColor = colorThief.getColor(image);
// Log the RGB values of the dominant color
console.log('Dominant color:', dominantColor);
// Set background colors using RGB values
image1.style.backgroundColor = `rgb(${dominantColor[0]}, ${dominantColor[1]}, ${dominantColor[2]})`;
image2.style.backgroundColor = `rgb(${dominantColor[0]}, ${dominantColor[1]}, ${dominantColor[2]})`;
image3.style.backgroundColor = `rgb(${dominantColor[0]}, ${dominantColor[1]}, ${dominantColor[2]})`;
};
</script>
</body>
</html>