标签:har .data site int 基础上 可见 osi er图 设置
在上传图片前需要对图片进行编辑,我选用的是cropperjs插件
绘制圆图的主要思路首先是将图片选取框中的可见区域设置为圆形,再在上传图片时在原图的基础上通过JS选取出一个圆图,再将选取的圆图上传到后台接口
.cropper-view-box, .cropper-face {
border-radius: 50%;
}
function getRoundedCanvas(){
var crop=(...).data("cropper"); //获取crop对象
var sourceCanvas=crop.getCroppedCanvas();
var canvas = document.createElement(‘canvas‘);
var context = canvas.getContext(‘2d‘);
var width = sourceCanvas.width;
var height = sourceCanvas.height;
canvas.width = width;
canvas.height = height;
context.imageSmoothingEnabled = true;
context.drawImage(sourceCanvas, 0, 0, width, height);
context.globalCompositeOperation = ‘destination-in‘;
context.beginPath();
context.arc(width / 2, height / 2, Math.min(width, height) / 2, 0, 2 * Math.PI, true);
context.fill();
return canvas;
}
var dataurl=canvas.toDataURL("image/png");
var arr = dataurl.split(‘,‘), mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
while(n--){
u8arr[n] = bstr.charCodeAt(n);
}
var filename=(...);
var f=new File([u8arr],filename,{type:"image/png"});
过程中查阅的文档:
标签:har .data site int 基础上 可见 osi er图 设置
原文地址:https://www.cnblogs.com/yumikobu/p/9897179.html