【发布时间】:2021-05-01 02:27:34
【问题描述】:
我一直试图将图像显示为椭圆形,但没有成功。
下面是我的代码 sn-p,它适用于圆形,但是当我们将图像从矩形转换为椭圆时会有间隙
如何在 html 画布中同时添加 rx、ry? 这就是当前代码将我的矩形图像转换为椭圆的方式,高度和宽度存在差距,它们不准确。
示例输出图像:
fabric.util.loadImage(imageURL, function (img) {
var oImg = new fabric.Image(img);
if (slot.image_shape == "ellipse") {
let shadow = (options && options.shadow) || {
affectStroke: true,
};
const radius =
oImg.width < oImg.height ? oImg.width / 2 : oImg.height / 2;
oImg.set({
clipTo: function (ctx) {
return ctx.arc(0, 0, radius, 0, Math.PI * 2, false);
},
});
}
【问题讨论】:
-
我不熟悉fabric.js,但是如果你想从图像创建一个椭圆形,为什么不使用css呢? (边框半径,框阴影)stackoverflow.com/questions/26961221/how-to-make-an-oval-in-css
标签: javascript image canvas html5-canvas fabricjs