Last active
February 29, 2020 20:04
-
-
Save rakibhasansabbir/a0b269f3acf2019d06cb4b9e1e09d886 to your computer and use it in GitHub Desktop.
HTML canvas rounded image draw under clipping area
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// save the context in its unaltered state | |
ctx.save(); | |
// fill canvas with black | |
ctx.fillStyle="black"; | |
ctx.fillRect(0,0,canvas.width,canvas.height); | |
// create clipping region which will display portion of image | |
// The image will only be visible inside the circular clipping path | |
ctx.beginPath(); | |
ctx.arc(100,100,100,0,Math.PI*2); | |
ctx.closePath(); | |
ctx.clip(); | |
// draw the image into the clipping region | |
ctx.drawImage(img,0,0); | |
// restore the context to its unaltered state | |
ctx.restore(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment