Created
May 9, 2013 20:15
-
-
Save wescleymatos/5550229 to your computer and use it in GitHub Desktop.
Este código exibe o preview de uma imagem e recupera seu tamanho original.
This file contains hidden or 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
<html> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> | |
<script src="http://fancyapps.com/fancybox/source/jquery.fancybox.pack.js?v=2.1.4"></script> | |
<link rel="stylesheet" type="text/css" href="http://fancyapps.com/fancybox/source/jquery.fancybox.css?v=2.1.4" media="screen" /> | |
<style type="text/css"> | |
#imgPreview {width: 100px;} | |
</style> | |
<script> | |
var reader = new FileReader(); | |
reader.onload = onLoadFile; | |
function onLoadFile(e) { | |
$("#imgPreview").attr('src', e.target.result); | |
$("#single_1").attr('href', e.target.result); | |
} | |
function preSizeCalc() { | |
var file = document.getElementById('fileImg'); | |
if(reader){ | |
reader.readAsDataURL(file.files[0]); | |
} else { | |
log("Seu navegador não tem suporte a HTML5, troque por um mais recente"); | |
} | |
} | |
$(document).ready(function(){ | |
$("#fileImg").change(function(){ | |
preSizeCalc(); | |
}); | |
$("#imgPreview").load(function(){ | |
var image = new Image(); | |
image.src = $(this).attr('src'); | |
alert(image.width); | |
}); | |
}); | |
</script> | |
<body> | |
<h1>File API</h1> | |
<div class="escondefile"> | |
<input type="file" id="fileImg"/><br/> | |
</div> | |
<p>Preview:</p> | |
<a id="single_1" href="" title=""> | |
<img id="imgPreview"/> | |
</a> | |
<label id="output"/><br/> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment