我有Laravel应用程序,我需要上传图像配置文件,我使用的是Croppie-js ,并且在上传之前需要剪切配置文件图像,因此我尝试了此代码,但无法正常工作。
图像将以全宽和全高上传!
Laravel的代码正在寻找并起作用。
只需在上传前调整图像大小即可。
HTML代码:
<div class="field"> <label class="label">Profile Image</label> <div class="control"> <input type="file" name="image" id="image_file" class="input" required> </div> <div id="upload-demo"></div> </div>
JS代码:
<script> var resize = $('#upload-demo').croppie({ enableExif: true, enableOrientation: true, viewport: { width: 200, height: 200, type: 'circle' }, boundary: { width: 500, height: 300 } }); $('#image_file').on('change', function () { var reader = new FileReader(); reader.onload = function (e) { resize.croppie('bind',{ url: e.target.result }).then(function(){ console.log('jQuery bind complete'); }); } reader.readAsDataURL(this.files[0]); }); </script>