我正在使用Croppie裁剪和上传图像。一切正常,除了我无法在上传之前设置默认图像。如果有人提供帮助,我将不胜感激:
这是我的javascript代码:
function demoUpload() {
var $uploadCrop;
function readFile(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('.upload-demo').addClass('ready');
$uploadCrop.croppie('bind', {
url: e.target.result
}).then(function(){
console.log('jQuery bind complete');
});
}
reader.readAsDataURL(input.files[0]);
}
else {
swal("Sorry - you're browser doesn't support the FileReader API");
}
}
$uploadCrop = $('#upload-demo').croppie({
viewport: {
width: 300,
height: 300,
type: 'rawcanvas'
},
});
$('#upload').on('change', function () { readFile(this); });
$('.upload-result').on('click', function (ev) {
$uploadCrop.croppie('result', {
type: 'canvas',
size: 'viewport'
}).then(function (resp) {
popupResult({
src: resp
});
$uploadCrop.croppie('bind', {
url: resp
});
// $('.cr-image').attr('src',resp).removeAttr('style');
//$('.cr-image').attr('style','width:300px');
//$('.cr-image').attr('aria-valuenow','0.1563');
$('.image_cropped').val(resp);
//$('#upload-demo').html('<img src="'+resp+'">');
});
});
}
演示图片:
我用谷歌搜索了很多,但找不到解决方案。Croppie 文档对我也不起作用。:(谢谢