fabric.Image的prototype
重要的原型方法
scaleToWidth: ƒ ()
scaleToHeight: ƒ ()
getScaledHeight: ƒ ()
getScaledWidth: ƒ ()
fabric.Image.fromURL(url, function (oImg) {
oImg.scaleToWidth(); // 按给定的宽将整个图片缩放,高也会按比例跟着改变
oImg.scaleToHeight();
oImg.getScaledHeight();
oImg.getScaledWidth();
}
// 图片裁剪实例
var img = document.getElementById("img");
image = new fabric.Image(img, {
clipPath: new fabric.Rect({
top: 0,
left: 0,
width: this.canvas.width,
height: this.canvas.height,
fill: "silver",
stroke: "silver",
strokeDashArray: [5, 5],
absolutePositioned: true,
lockMovementX: true, // 禁止水平移动
lockMovementY: true, // 禁止垂直移动
hasRotatingPoint: false, // 无旋转点
hasControls: true, // 编辑框
selectable: false // 不可选中
})
});
image.crossOrigin = "anonymous"; // 可跨域访问图片
原文链接:https://blog.csdn.net/weixin_39388536/article/details/103719600