Javascript 使用裁剪器js进行旋转
我正在使用croppers库,我在一些Android设备上实现它时遇到了问题。照片是垂直拍摄的,我得到了水平方向。我尝试用铜js调整水平或垂直旋转部分(90或180度),但没有成功 我在meteor中工作我留下了一部分代码。 html部分Javascript 使用裁剪器js进行旋转,javascript,meteor,cropperjs,Javascript,Meteor,Cropperjs,我正在使用croppers库,我在一些Android设备上实现它时遇到了问题。照片是垂直拍摄的,我得到了水平方向。我尝试用铜js调整水平或垂直旋转部分(90或180度),但没有成功 我在meteor中工作我留下了一部分代码。 html部分 <div class=" col-xs-6 "> <div> {{#if photo_2}} <img class="img-responsive" src='{{photo_2}}' a
<div class=" col-xs-6 ">
<div>
{{#if photo_2}}
<img class="img-responsive" src='{{photo_2}}' alt="" style="width:1531px;height:114px;"/>
{{else}}
<img class="img-responsive" src="/persona2.png" alt="" />
{{/if}}
</div>
<div class="col-xs-12">
<button type="" class="btn-default btn-picture btn" id="btn2"><i class="fa fa-plus plus" aria-hidden="true"></i></button>
</div>
</div>
<input type="hidden" id="photoid">
<input id="file-upload" style="display: none;" type="file" accept="image/*" />
<div id="snackbar">
<img class="img-responsive cameraphoto" id="cameraphoto" src="/camera-icon-55.png" alt="" />
<img class="img-responsive" id="explorer" onclick="$('#file-upload').click();" src="/camera-icon-56.png" alt="" />
<img class="img-responsive" id="delete" src="/delete.png" />
</div>
<div id="crops" style="display: none; background-color: black;height: 100vh;">
<canvas id="canvas" height="5" width="5" style="display: none;"></canvas>
<img id="target" style="max-width: 100%" />
<img id="targeted" style="max-width: 100%" />
<div style="position: absolute; margin-top: 145px; bottom: 20px; width: 100%;text-align: center;">
<center>
<img class="img-responsive" id="Save" src="/save.png" alt="" style="width: 48px;margin-left: -78px;"/>
<img class="img-responsive" id="cancel" src="/cancel.png" alt="" style="width: 54px;margin-left: 62px;margin-top: -50px;"/>
<image id="Browser" src=""/>
</center>
<input type="hidden" id="photoid">
</div>
<input type="hidden" name="imgX1" id="imgX1" />
<input type="hidden" name="imgY1" id="imgY1" />
<input type="hidden" name="imgWidth" id="imgWidth" />
<input type="hidden" name="imgHeight" id="imgHeight" />
<input type="hidden" name="imgrotate" id="imgrotate" />
<input type="hidden" name="imgscaleX" id="imgscaleX" />
<input type="hidden" name="imgscaleY" id="imgscaleY" />
</div>
我的解决方案基于以下内容
'click #rotateL': function(e, instance){
$('#target').cropper('rotate', -90);
},
'click #rotateR': function(e, instance){
$('#target').cropper('rotate', 90);
},
'click #Save' : function(e) {
$(".loader").fadeIn("slow");
e.preventDefault();
var photoid = $('#photoid').val();
var canvas = $('#target').cropper('getCroppedCanvas');
console.log(canvas)
var dataURL = canvas.toDataURL("image/jpeg");
var photo = {
srcData : dataURL,
userid : Meteor.userId(),
photo_id : photoid
}
Meteor.call('updatePhoto',photo,function(err) {
if (!err) {
$('#photos').show();
$('#crops').hide();
canvas.height = 0;
canvas.width = 0;
//page relod is better than
//document.getElementById('target').src="";
FlowRouter.go('/search');
FlowRouter.go('/addphoto');
}
});
},
请将解决方案发布为答案,而不是问题的更新。这是为了避免混淆。您可以在中找到您的更改。谢谢。在找到解决方案并编辑它之后,我已经准备好将我自己的问题标记为答案。你问题的重点是说明问题。答案的关键是回答你的问题。在同一页上看到问题和答案会有所帮助。如果你解决了这个问题,并用一个解决方案替换,那么它对任何人都没有用。请将解决方案作为答案发布,并将其标记为已接受。
'click #rotateL': function(e, instance){
$('#target').cropper('rotate', -90);
},
'click #rotateR': function(e, instance){
$('#target').cropper('rotate', 90);
},
'click #Save' : function(e) {
$(".loader").fadeIn("slow");
e.preventDefault();
var photoid = $('#photoid').val();
var canvas = $('#target').cropper('getCroppedCanvas');
console.log(canvas)
var dataURL = canvas.toDataURL("image/jpeg");
var photo = {
srcData : dataURL,
userid : Meteor.userId(),
photo_id : photoid
}
Meteor.call('updatePhoto',photo,function(err) {
if (!err) {
$('#photos').show();
$('#crops').hide();
canvas.height = 0;
canvas.width = 0;
//page relod is better than
//document.getElementById('target').src="";
FlowRouter.go('/search');
FlowRouter.go('/addphoto');
}
});
},