在我的应用程序中,我使用croppie 裁剪图像然后预览然后上传裁剪的图像。我已经将图像裁剪为预览,但我无法在我的输入字段中设置该裁剪值。
<div class="modal fade" id="myModal" role="dialog" style="margin-top: 70px;">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Upload Profile Picture</h4>
</div>
<form method="POST" action="picuploaddb.php" enctype="multipart/form-data">
<div class="modal-body">
<input type="hidden" name="teacherid" value="<?php echo $myteacherid;?>">
<input type="file" class="form-control" id="upload_image" name="profile_pic"> <!-- add id-->
<input type="file" style="display:none" class="form-control" id="upload_preview" name="profile_picpreview">
<img class='img-circle' id="preview" name="profile_preview"/>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success upload">Upload</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
在此模式中,我曾经选择文件并在裁剪预览并从此模式上传之后。我无法在第二个输入字段中设置裁剪图像。
$(document).ready(function(){
$image_crop = $('#image_demo').croppie({
enableExif: true,
viewport: {
width:220,
height:250,
type:'circle' //circle
},
boundary:{
width:300,
height:300
}
});
$('#upload_image').on('change', function(){
var reader = new FileReader();
reader.onload = function (event) {
$image_crop.croppie('bind', {
url: event.target.result
}).then(function(){
console.log('jQuery bind complete');
});
}
reader.readAsDataURL(this.files[0]);
$('#uploadimageModal').modal('show');
});
$('.crop_image').click(function(event){
$image_crop.croppie('result', {
type: 'canvas',
size: 'viewport'
}).then(function(resp){
$('#uploadimageModal').modal('hide');
$('#upload_image').hide();
$('#preview').attr('src',resp);
$('#upload_preview').attr('name',resp);
$('#upload_preview').show();//i want cropped image inside it
});
});
});
这是我的croppie js。我想在 upload_preview 输入字段中设置裁剪图像。请帮助我。谢谢。