简体   繁体   English

jQuery裁剪图片,然后上传croppie插件

[英]jquery crop image before upload croppie plugin

Hello I'm facing difficulty in saving the cropped image in CakePHP using croppie plugin image is cropped but when saving the image it saves the whole image not the cropped image, after cropping the src of crop image it is correct but whenever I try to save it, it saves the whole default image. 您好,我在使用croppie插件图像裁剪 CakePHP中保存裁剪后的图像时遇到了困难,但是在保存图像时,它保存的是整个图像而不是裁剪后的图像,裁剪裁剪后的图像的src是正确的,但是每当我尝试保存时它将保存整个默认图像。

 $uploadCrop = $('#upload-demo').croppie({ enableExif: true, viewport: { width: 180, height: 180, type: 'circle' }, boundary: { width: 190, height: 190 }, showZoomer: false }); $('#my_file').on('change', function() { $('#tttssss').show(); $('#user-select-image').hide(); var reader = new FileReader(); reader.onload = function(e) { $uploadCrop.croppie('bind', { url: e.target.result }).then(function() { console.log('jQuery bind complete'); }); } reader.readAsDataURL(this.files[0]); }); $('.upload-result').on('click', function(ev) { $uploadCrop.croppie('result', { type: 'canvas', size: 'viewport' }) .then(function(resp) { $('#user-select-image').attr('src', resp); $('#user-select-image').show(); $("#tttssss").hide(); }); }); $(document).ready(function() { $("#user-select-image").click(function() { $("input[id='my_file']").click(); }); }); 
 <div id="tttssss" style="display:none;"> <div id="upload-demo"> </div> <div style="width:70%;margin: 0 auto;"> <a class="btn btn-success upload-result" rel="<?php //echo $imge['User']['id'] ?>">Upload Image</a> </div> </div> <?php echo $this->Html->image($fileuser, array('class' => 'img-circl', 'id' => 'user-select-image', 'style' => 'margin-top:30px!important;')); ?> <?php echo $this->Form->file('User.profile_img', array('id' => 'my_file', 'style' => 'display:none;')); ?> 

Upload the image it upload the whole image 上传图片上传整个图片

This is my code 这是我的代码

In function: $uploadCrop.croppie('result', { type: 'canvas', size: 'viewport' }) 在函数中: $uploadCrop.croppie('result', { type: 'canvas', size: 'viewport' })

 .then(function(resp) { $('#user-select-image').attr('src', resp.target.result); $('#user-select-image').show(); $("#tttssss").hide(); });}); 

You must use: resp.toDataURL() instead of resp.target.result 您必须使用: resp.toDataURL()而不是resp.target.result

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM