I want to draw a image which is Square to canvas and round it.
My code is
const x = 100
const y = 100
const iconRadius = 60
const iconWidth = iconRadius * 2
const iconHeight = iconRadius * 2
ctx.beginPath()
ctx.moveTo(x + iconRadius, y)
ctx.lineTo(x + iconWidth - iconRadius, y)
ctx.quadraticCurveTo(x + iconWidth, y, x + iconWidth, y + iconRadius)
ctx.lineTo(x + iconWidth, y + iconHeight - iconRadius)
ctx.quadraticCurveTo(
x + iconWidth,
y + iconHeight,
x + iconWidth - iconRadius,
y + iconHeight
)
ctx.lineTo(x + iconRadius, y + iconHeight)
ctx.quadraticCurveTo(x, y + iconHeight, x, y + iconHeight - iconRadius)
ctx.lineTo(x, y + iconRadius)
ctx.quadraticCurveTo(x, y, x + iconRadius, y)
ctx.closePath()
ctx.clip()
drawImageProp(ctx, userIconImage, x, y, iconWidth, iconHeight)
I use this solution Looks like it is not a Round image, I donot know how to fix it.