"Color Palette from Image"
Bootstrap 4.1.1 Snippet by SOJITRA

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
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/color-thief/2.3.0/color-thief.min.js" type="text/javascript"></script>
<div class="container">
<h1 class="font-weight-light text-center text-lg-left mt-4 mb-0">Color Palette from Image<small class="float-right">Click Image</small></h1>
<hr class="mt-2 mb-5">
<div class="row text-center text-lg-left">
<div class="col-lg-3 col-md-4 col-6">
<div class="d-block">
<img class="img-fluid img-thumbnail" alt="" crossOrigin="anonymous">
</div>
</div>
<div class="col-lg-3 col-md-4 col-6">
<div class="d-block">
<img class="img-fluid img-thumbnail" alt="" crossOrigin="anonymous">
</div>
</div>
<div class="col-lg-3 col-md-4 col-6">
<div class="d-block">
<img class="img-fluid img-thumbnail" alt="" crossOrigin="anonymous">
</div>
</div>
<div class="col-lg-3 col-md-4 col-6">
<div class="d-block">
<img class="img-fluid img-thumbnail" alt="" crossOrigin="anonymous">
</div>
</div>
<div class="col-lg-3 col-md-4 col-6">
<div class="d-block">
<img class="img-fluid img-thumbnail" alt="" crossOrigin="anonymous">
</div>
</div>
<div class="col-lg-3 col-md-4 col-6">
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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
.d-block {
margin-bottom: 30px
}
.d-block:after {
display: table;
width: 100%;
clear: both;
content: '';
}
.img-thumbnail {
border: 0;
border-radius: 0;
}
.color-palette h6 {
margin: 15px 0;
}
.color-palette h6:first-child {
margin-top: 0;
}
.color-palette h6:last-child {
margin-bottom: 0;
}
.main-color {
display: inline-block;
margin: 0 auto;
vertical-align: middle;
border: 1px solid;
border-radius: 30px;
overflow: hidden;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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
const afterRisizeListenersList = [];
function triggerAfterResizeListeners() {
afterRisizeListenersList.forEach(function(o) {
if (typeof o.callBack === "function") {
o.callBack.apply(null, o.arguments);
}
})
}
/**/
var unsplash = '';
var colorThief = new ColorThief();
var imgs = document.querySelectorAll('img');
$.ajax({
url: "https://api.unsplash.com/photos/?&client_id=f0afe99aaf46a21c572d5dd3d620f3cf96e287a52e8af381f4bbaa5729a02215",
success: function(result) {
unsplash = result;
$('img').each(function(i) {
$(this).attr('src', unsplash[i].urls.small);
});
$("img").one("load", function() {
//colorPalette(this);
var c = colorThief.getColor(this);
$(this).css('background',rgbToHex(c[0], c[1], c[2]));
$(this).on('click', function() {
var modal = $('#myModal');
paletteModal(this, modal);
})
}).each(function(i) {
afterRisizeListenersList.push({
callBack: function() {
colorPalette(this);
},
arguments: []
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: