如何裁剪图像?它不起作用。请建议我 [英] How Do I Make The Cropping Of Image ?It Is Not Working.Please Suggest Me
本文介绍了如何裁剪图像?它不起作用。请建议我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<script>
function onFileLoad(e) {
$('#cropbox').html('<img src="'+e.target.result +'"/>');
}
function displayPreview(files) {
var reader = new FileReader();
reader.onload = onFileLoad;
reader.readAsDataURL(files[0]);
}
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/jquery.Jcrop.js"></script>
<link rel="stylesheet" href="css/demos.css" type="text/css" />
<link rel="stylesheet" href="css/jquery.Jcrop.css" type="text/css" />
<script type="text/javascript">
$(function(){
$('#cropbox').Jcrop({
aspectRatio: 1,
onSelect: updateCoords
});
});
function updateCoords(c)
{
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
};
function checkCoords()
{
if (parseInt($('#w').val())) return true;
alert('Please select a crop region then press submit.');
return false;
};
</script>
<body style="text-align:center; margin-top:50px; width:50%;">
<form action="" method="post" enctype="multipart/form-data" >
<fieldset style="text-align:center; height:200px; color:#0000FF; height:200%; width:188%">
<legend style="border: #0000CC 1px solid;"> Upload Image</legend>
<table width="200" border="0" align="center" cellpadding="6px">
<tr>
<td height="20px;">Image</td>
<br/>
<td><input type="file" name="image" id="image" onChange="displayPreview(this.files);"/>
</td>
</tr>
<td id="abc"></td>
</table>
<br/>
<input type="submit" value="submit" name="submit">
<br/>
<div id="cropbox" class='imagem_artigo' ></div>
<form action="form.php" method="post" onSubmit="return checkCoords();" enctype="multipart/form-data" >
<input type="text" id="x" name="x" />
<input type="text" id="y" name="y" />
<input type="text" id="w" name="w" />
<input type="text" id="h" name="h" />
<input type="submit" value="Crop Image" class="btn btn-large btn-inverse" name="submit" />
</form>
<br>
<br>
</fieldset>
</form>
</body>
推荐答案
(' #cropbox')。html(' < img src =' + e.target.result + ' />');
}
function displayPreview(files){
var reader = new FileReader();
reader.onload = onFileLoad;
reader.readAsDataURL(files [ 0 ]);
}
< / 脚本 >
< script src = https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js > < / script >
< script src = < span class =code-keyword> js / jquery.min.js > < < /跨度> <跨度class =code-keyword> / script >
< script src = js / jquery.Jcrop.js > < / script >
< link rel = 样式表 href < span class =code-keyword> = css / demos.css 类型 = text / css / >
< link rel = stylesheet href = css / jquery.Jcrop.css type = text / css / >
< script < /秒pan> type = text / javascript >
('#cropbox').html('<img src="'+e.target.result +'"/>'); } function displayPreview(files) { var reader = new FileReader(); reader.onload = onFileLoad; reader.readAsDataURL(files[0]); } </script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> <script src="js/jquery.min.js"></script> <script src="js/jquery.Jcrop.js"></script> <link rel="stylesheet" href="css/demos.css" type="text/css" /> <link rel="stylesheet" href="css/jquery.Jcrop.css" type="text/css" /> <script type="text/javascript">
( function (){
(' #cropbox ')。Jcrop({
aspectRatio: 1 ,
onSelect:updateCoords
});
});
function updateCoords(c)
{
('#cropbox').Jcrop({ aspectRatio: 1, onSelect: updateCoords }); }); function updateCoords(c) {
这篇关于如何裁剪图像?它不起作用。请建议我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文