Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
pushing to gh-pages
- Loading branch information
James Cryer
committed
Feb 21, 2013
0 parents
commit fe90ebb
Showing
7 changed files
with
940 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Resemble.js | ||
========== | ||
|
||
Analyse and compare images with Javascript and HTML5. [Resemble.js Demo](http://huddle.github.com/resemble.js/) |
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 |
---|---|---|
@@ -0,0 +1,118 @@ | ||
$(function(){ | ||
var $target = $('#drop-zone'); | ||
|
||
function dropZone($target, onDrop){ | ||
$target. | ||
bind('dragover', function(){ | ||
$target.addClass( 'drag-over' ); | ||
return false; | ||
}). | ||
bind("dragend", function () { | ||
$target.removeClass( 'drag-over' ); | ||
return false; | ||
}). | ||
bind("mouseout", function () { | ||
$target.removeClass( 'drag-over' ); | ||
return false; | ||
}). | ||
bind("drop", function(event) { | ||
var file = event.originalEvent.dataTransfer.files[0]; | ||
|
||
event.stopPropagation(); | ||
event.preventDefault(); | ||
|
||
$target.removeClass( 'drag-over' ); | ||
|
||
var droppedImage = new Image(); | ||
var fileReader = new FileReader(); | ||
|
||
fileReader.onload = function (event) { | ||
droppedImage.src = event.target.result; | ||
$target.html(droppedImage); | ||
}; | ||
|
||
fileReader.readAsDataURL(file); | ||
|
||
onDrop(file); | ||
}); | ||
} | ||
|
||
dropZone($target, function(file){ | ||
|
||
resemble(file).onComplete(function(data){ | ||
$('#image-data').show(); | ||
$('#red').css('width',data.red+'%'); | ||
$('#green').css('width',data.green+'%'); | ||
$('#blue').css('width',data.blue+'%'); | ||
$('#brightness').css('width',data.brightness+'%'); | ||
}); | ||
|
||
}); | ||
|
||
function onComplete(data){ | ||
var time = Date.now(); | ||
var diffImage = new Image(); | ||
diffImage.src = data.getImageDataUrl(); | ||
|
||
$('#image-diff').html(diffImage); | ||
|
||
$(diffImage).click(function(){ | ||
window.open(diffImage.src, '_blank'); | ||
}); | ||
|
||
$('#buttons').show(); | ||
|
||
if(data.misMatchPercentage == 0){ | ||
$('#thesame').show(); | ||
$('#diff-results').hide(); | ||
} else { | ||
$('#mismatch').text(data.misMatchPercentage); | ||
if(!data.isSameDimensions){ | ||
$('#differentdimensions').show(); | ||
} else { | ||
$('#differentdimensions').hide(); | ||
} | ||
$('#diff-results').show(); | ||
$('#thesame').hide(); | ||
} | ||
} | ||
|
||
var file1; | ||
var file2; | ||
var resembleControl; | ||
dropZone($('#dropzone1'), function(file){ | ||
file1 = file; | ||
if(file2){ | ||
resembleControl = resemble(file).compareTo(file2).onComplete(onComplete); | ||
} | ||
}); | ||
dropZone($('#dropzone2'), function(file){ | ||
file2 = file; | ||
if(file1){ | ||
resembleControl = resemble(file).compareTo(file1).onComplete(onComplete); | ||
} | ||
}); | ||
|
||
|
||
var buttons = $('#raw, #colors, #antialising'); | ||
|
||
buttons.click(function(){ | ||
var $this = $(this); | ||
|
||
buttons.removeClass('active'); | ||
$this.addClass('active'); | ||
|
||
if($this.is('#raw')){ | ||
resembleControl.ignoreNothing(); | ||
} | ||
else | ||
if($this.is('#colors')){ | ||
resembleControl.ignoreColors(); | ||
} | ||
else | ||
if($this.is('#antialising')){ | ||
resembleControl.ignoreAntialiasing(); | ||
} | ||
}); | ||
|
||
}); |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
|
||
h1 { | ||
text-align: center; | ||
} | ||
|
||
body { | ||
padding-top: 60px; | ||
} | ||
|
||
footer { | ||
margin-top: 45px; | ||
padding: 35px 0 36px; | ||
border-top: 1px solid #e5e5e5; | ||
} | ||
|
||
.drop-zone{ | ||
border: 10px dashed #ccc; | ||
color: #ccc; | ||
font-size: 32px; | ||
height: 400px; | ||
line-height: 400px; | ||
text-align: center; | ||
width: 400px; | ||
overflow: hidden; | ||
position: relative; | ||
} | ||
.drop-zone.drag-over{ | ||
border: 10px dashed #0088CC; | ||
} | ||
.drop-zone img { | ||
width: 400px; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
} | ||
|
||
.small-drop-zone{ | ||
margin-top: 20px; | ||
margin-left: 90px; | ||
border: 10px dashed #ccc; | ||
color: #ccc; | ||
font-size: 32px; | ||
height: 330px; | ||
line-height: 330px; | ||
text-align: center; | ||
width: 330px; | ||
overflow: hidden; | ||
position: relative; | ||
} | ||
.small-drop-zone.drag-over{ | ||
border: 10px dashed #0088CC; | ||
} | ||
.small-drop-zone img { | ||
width: 330px; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
} | ||
#image-diff { | ||
margin-left: 0px; | ||
margin-top: 90px; | ||
border-style: solid; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,165 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | ||
<title>Resemble.js : Image analysis</title> | ||
<meta name="description" content=""> | ||
<meta name="viewport" content="width=device-width"> | ||
<link rel="stylesheet" href="libs/twitter-bootstrap/bootstrap.min.css"> | ||
<link rel="stylesheet" href="demoassets/resemble.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<header> | ||
<div class="page-header"> | ||
<h1>Resemble.js : Image analysis and comparison</h1> | ||
</div> | ||
</header> | ||
|
||
<section role="main"> | ||
<div class="row"> | ||
<div class="span12"> | ||
<div class="hero-unit"> | ||
<div class="row"> | ||
<div class="span6"> | ||
<p> | ||
<div id="drop-zone" class="drop-zone"> | ||
Drop image here. | ||
</div> | ||
</p> | ||
</div> | ||
<div class="span4"> | ||
<h2>What is this?</h2> | ||
<p> | ||
Resemble.js analyses and compares images with HTML5 canvas and JavaScript. | ||
</p> | ||
<p> | ||
<strong>Try it for yourself.</strong> | ||
</p> | ||
<div id="image-data" style="display:none"> | ||
|
||
RGB | ||
<div class="progress progress-danger"> | ||
<div id="red" class="bar" style="width: 0%;"></div> | ||
</div> | ||
<div class="progress progress-success"> | ||
<div id="green" class="bar" style="width: 0%;"></div> | ||
</div> | ||
<div class="progress"> | ||
<div id="blue" class="bar" style="width: 0%;"></div> | ||
</div> | ||
|
||
Brightness | ||
<div class="progress progress-warning"> | ||
<div id="brightness" class="bar" style="width: 0%;"></div> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="span12"> | ||
<div class="row"> | ||
<div class="span6"> | ||
<div id="dropzone1" class="small-drop-zone"> | ||
Drop first image | ||
</div> | ||
<div id="dropzone2" class="small-drop-zone"> | ||
Drop second image | ||
</div> | ||
</div> | ||
<div class="span6"> | ||
<h2>Compare two images?</h2> | ||
<p> | ||
Drop two images on the boxes to the left. The box below will show a generated 'diff' image, pink areas show mismatch. This example best works with two very similar but slightly different images. Try for yourself! | ||
</p> | ||
<div id="image-diff" class="small-drop-zone"> | ||
Diff will appear here. | ||
</div> | ||
<br/> | ||
<div class="btn-group" id="buttons" style="display:none"> | ||
<button class="btn active" id="raw">Ignore nothing</button> | ||
<button class="btn" id="colors">Ignore colors</button> | ||
<button class="btn" id="antialising">Ignore antialiasing</button> | ||
</div> | ||
<br/> | ||
<br/> | ||
<div id="diff-results" style="display:none;"> | ||
<p> | ||
<strong>The second image is <span id="mismatch"></span>% different compared to the first. | ||
<span id="differentdimensions" style="display:none;">And they have different dimensions.</span></strong> | ||
</p> | ||
<p> | ||
Use the buttons above to change the comparison algorithm. Perhaps you don't care about color? Annoying antialiasing causing too much noise? Resemble.js offers multiple comparison options. | ||
</p> | ||
</div> | ||
|
||
<p id="thesame" style="display:none;"> | ||
<strong>These images are the same!</strong> | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<br/><br/> | ||
<div class="row"> | ||
<div class="span6"> | ||
<h2>Why?</h2> | ||
<p> | ||
Resemble.js can be used for any image analysis and comparison requirement you might have in the browser. However, it has been designed and built for use by the PhantomJS powered visual regression library <a href="https://github.com/Huddle/PhantomCSS" target="_blank">PhantomCSS</a>. PhantomCSS needs to be able to ignore antialiasing as this would cause differences between screenshots derived from different machines. | ||
</p> | ||
<p> | ||
Resemble.js uses the <a href="https://github.com/Huddle/PhantomCSS" target="_blank">HTML5 File API</a> to parse image data, and canvas for rendering image diffs. | ||
</p> | ||
<p> | ||
<br/> | ||
<a class="btn btn-large btn-primary" href="https://github.com/Huddle/Resemble.js"><strong>View project on Github</strong></a> | ||
</p> | ||
</div> | ||
<div class="span6"> | ||
<h2>How can I use it?</h2> | ||
<p>Retrieve basic analysis on image.</p> | ||
<pre> | ||
var api = resemble(fileData).onComplete(function(data){ | ||
return data; | ||
/* | ||
{ | ||
red: 255, | ||
green: 255, | ||
blue: 255, | ||
brightness: 255 | ||
} | ||
*/ | ||
});</pre> | ||
<p>Use resemble to compare two images.</p> | ||
<pre> | ||
resemble(file).compareTo(file2).onComplete(function(){ | ||
return data; | ||
/* | ||
{ | ||
misMatchPercentage : 100, // % | ||
isSameDimensions: true, // or false | ||
getImageDataUrl: function(){} | ||
} | ||
*/ | ||
});</pre> | ||
<p>Take a look at the <a href="demoassets/main.js" target="_blank">JavaScript for this demo page</a> from a better example</p> | ||
</div> | ||
</div> | ||
</section> | ||
|
||
<footer class="footer"> | ||
<p> | ||
Created by <a href="https://github.com/jamescryer">James Cryer</a> and the Huddle development team. | ||
</p> | ||
</footer> | ||
</div> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> | ||
<script src="resemble.js"></script> | ||
<script src="demoassets/main.js"></script> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.