[英]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.