Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 134 lines (99 sloc) 3.76 KB
<!doctype html>
<html class="no-js" lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link href='|Terminal+Dosis:400,700,600' rel='stylesheet' type='text/css'>
<title>Color Thief</title>
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="css/app.css">
<script src="js/libs/modernizr-2.0.6.min.js"></script>
<div id="container">
<h1>Color Thief</h1>
<h4><a href="">by Lokesh Dhakar</a></small></h4>
<p>A script for grabbing the dominant color or color palette from an image. Uses Javascript and the canvas tag to make it happen.</p>
<p><a href="">Read more on my blog</a> | <a href="">Get the code on Github</a>
<div id="main" role="main">
</div> <!--! end of #container -->
<script>window.jQuery || document.write('<script src="js/libs/jquery-1.6.2.min.js"><\/script>')</script>
<script src="js/libs/jquery.imagesloaded.js"></script>
<script src="js/libs/jquery.lettering.js"></script>
<script src="js/libs/mustache.js"></script>
<script src="js/libs/quantize.js"></script>
<script src="js/color-thief.js"></script>
<!-- Using Mustache templating -->
<script id='template' type='text/x-mustache'>
<div class="imageSection clearfix {{class}} ">
<div class="imageWrap">
<img class="targetImage" src="img/{{file}}" data-colorcount="{{colorCount}}" />
<div class="colors">
<div class="function dominantColor clearfix">
<h3>Dominant Color</h3>
<div class="swatches clearfix"></div>
<div class="function medianCutPalette clearfix">
<div class="swatches clearfix"></div>
// Use mustache.js templating to create layout
var imageArray = { images: [
{"file": "3.jpg"},
{"file": "4.jpg"},
{"file": "5.jpg"},
{"file": "logo1.png"},
{"file": "icon1.png", "colorCount": "4", "class": "fbIcon"}
var html = Mustache.to_html($('#template').html(), imageArray);
// Use lettering.js to give letter by letter styling control for the h1 title
// Once images are loaded, loop through each one, getting dominant color
// and palette and displaying them.
var imageSection = $(this).closest('.imageSection'),
// Dominant Color
var dominantColor = getDominantColor(this);
swatchEl = $('<div>', {
'class': 'swatch'
}).css('background-color','rgba('+dominantColor.r+','+dominantColor.g+ ','+dominantColor.b+', 1)');
imageSection.find('.dominantColor .swatches').append(swatchEl);
// Palette
var colorCount = $(this).attr('data-colorcount')? $(this).data('colorcount'): 10;
var medianPalette = createPalette(this, colorCount);
var medianCutPalette = imageSection.find('.medianCutPalette .swatches');
$.each(medianPalette, function(index, value){
swatchEl = $('<div>', {
'class': 'swatch'
}).css('background-color','rgba('+value[0]+','+value[1]+ ','+value[2]+', 1)');
<script src="" type="text/javascript"></script>
<script type="text/javascript">
_uacct = "UA-2196019-1";