[英]Image preview before upload and crop
我正在制作允許管理員上傳圖像的表格。 我希望他們能夠在上傳之前預覽此圖像。 它將顯示為特定大小,他們將能夠單擊圖像以打開頁面內窗口進行裁剪。
jQuery圖像裁剪: http : //jsfiddle.net/UydpR/2/
我的代碼,很抱歉,我試圖擺弄小提琴,但無法正常工作!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link class="jsbin" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"></script>
<meta charset=utf-8 />
<title>Image Test</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
</style>
</head>
<body>
<input type='file' onchange="readURL(this);" />
<img id="blah" src="#" alt="your image" />
<script type="text/javascript">
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah')
.attr('src', e.target.result)
.width(150)
.height(200);
};
reader.readAsDataURL(input.files[0]);
}
}
</script>
</body>
</html>
我也希望默認顯示一些東西,而不是找不到圖像的徽標。 我會說一個“沒有上傳圖片”或其他。
謝謝您的幫助,蒂姆,祝福您
這是在Web瀏覽器中加載圖像以進行預覽的示例。 希望對您有幫助
<script>
function readImage(input) {
if ( input.files && input.files[0] ) {
var FR= new FileReader();
FR.onload = function(e) {
$('#img').attr( "src", e.target.result );
//$('#base').text( e.target.result ); //this is the base64 encoded image
var img = e.target.result;
};
FR.readAsDataURL( input.files[0] );
}
}
</script>
<input type='file' id="asd" onchange="readImage( this )"/>
<img id="img" src="" />
<div id="base"></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.