我有一个使用Canvas Fabric JS创建某个东西的面板。Canvas上有许多占位符,比如矩形,我想在特定区域添加图像。我正在将该区域剪切,以便图像不会离开该区域。现在一切都正常工作,除了使用Canvas实例设置剪辑区域的角度(旋转不起作用)。
以下是我的代码:
var clipByName = function (bindClip) {
this.setCoords();
var clipRect = findByClipName(this.clipName);
var scaleXTo1 = (1 / this.scaleX);
var scaleYTo1 = (1 / this.scaleY);
bindClip.save();
var ctxLeft = -( this.width / 2 ) + clipRect.strokeWidth;
var ctxTop = -( this.height / 2 ) + clipRect.strokeWidth;
var ctxWidth = clipRect.width - clipRect.strokeWidth;
var ctxHeight = clipRect.height - clipRect.strokeWidth;
bindClip.translate(ctxLeft, ctxTop);
bindClip.rotate(this.angle *(Math.PI / 180) * -1);
bindClip.scale(scaleXTo1, scaleYTo1);
bindClip.beginPath();
bindClip.rect(
clipRect.left - this.oCoords.tl.x,
clipRect.top - this.oCoords.tl.y,
clipRect.width,
clipRect.height
);
console.log(bindClip);
bindClip.closePath();
bindClip.restore();
}
这是我想看到更改的URL。请尝试通过拖放添加图片。 https://purplle.com/collection/create-collection/?template=175
请按照以下说明进行操作:
- 搜索产品,例如Lakme,Ponds等。
- 将任何图像拖到产品占位符上。
移动图像时,裁剪区域仍未得到当前占位符(矩形)的角度。