I'm using this coverflow script on my website and I don't know how to output the canvas with rounded corners.
This is the code that draws the image
ctx.drawImage(image, cropLeft, cropTop, wid-2*cropLeft, hei-2*cropTop, 0, 0, newWidth, newHeight);
I read some tutorials using arc() or arcTo() functions but none of them we're using an image as object.
UPDATE1: I see that drawimage() has only the following parameters for drawing: • Images the same size and composition as the original • Images that are resized from the original • Images that are cropped from the original
So, I guess, it's not possible to draw images with rounded corners through canvas..
The problem with the clip() solution is that Chrome will render it with the borders non antialiased, as demonstrated in this question.
One solution would be to do it with globalCompositeOperation as Daniel says in his answer:
You can use
context.clip()
to draw an image that's clipped inside a rounded rectangleFirst draw a rectangle with rounded corners (no need to stroke or fill):
Then call context.clip which will cause all future drawings to be clipped inside the rect
Finally, draw your image inside that rectangle and your image will be clipped round.
Here is example code and a Fiddle: http://jsfiddle.net/m1erickson/FLaee/