I saw a similar question here but I have an array
of radius instead of a number
so it couldn't use +
operator.
The radius has 4 values: [top, right, bottom, left]
<Stage width={width} height={height}>
<Layer>
<Rect
width={width / 2}
height={height / 2}
x={20}
y={20}
fill=""
cornerRadius={10}
shadowEnabled={true}
shadowColor="#bada41"
shadowBlur={50}
shadowOffset={{ x: 10, y: 10 }}
shadowOpacity={1}
shadow={10}
/>
<Rect
width={width / 2}
height={height / 2}
x={20}
y={20}
cornerRadius={cornerRadius}
fill="palevioletred"
/>
<Group
clipFunc={(ctx: any) => {
ctx.beginPath()
ctx.moveTo(x + cornerRadius[0], y)
ctx.lineTo(x + width - cornerRadius[0], y)
ctx.quadraticCurveTo(x + width, y, x + width, y + cornerRadius[0])
ctx.lineTo(x + width, y + height - cornerRadius[1])
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - cornerRadius[1],
y + height
)
ctx.lineTo(x + cornerRadius[1], y + height)
ctx.quadraticCurveTo(x, y + height, x, y + height - cornerRadius[2])
ctx.lineTo(x, y + cornerRadius[2])
ctx.quadraticCurveTo(x, y, x + cornerRadius[3], y)
ctx.closePath()
}}
>
<Image
image={img}
width={width / 4}
height={height / 4}
x={40}
y={40}
fill="blue"
/>
</Group>
</Layer>
</Stage>
Codesandbox ???? https://codesandbox.io/s/clip-rounded-image-in-react-konva-09d2l?file=/src/App.tsx
How can I make the inner image the same shape as the outer one?