Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any css or javascript techniques to display a 'slice' of a circle image?

Tags:

javascript

css

I'm trying to write a program where users upload circular images like this deliciously warm pizza:enter image description here

The user then specifies the start and end of the arc in degrees so that a function will be called to display the same image, with a lower opacity on the leftover portion.

function cutPizza (startArcDegree, endArcDegree){
//This is where I need help    
}

cutPizza(150, 225);

enter image description here

Are there any css or javascript techniques to help me achieve this (Or any or ways for that matter)?

like image 413
user784637 Avatar asked Feb 29 '12 07:02

user784637


People also ask

How do you make an image a circle in CSS?

The main CSS property responsible for the circular shape is the border-radius property. Setting the radius of the corners to 50% of the width/height results in a circle.

How do I cut an image in CSS?

The border-image-slice CSS property divides the image specified by border-image-source into regions. These regions form the components of an element's border image.

How do you code a circle in JavaScript?

The arc() method creates an arc/curve (used to create circles, or parts of circles). Tip: To create a circle with arc(): Set start angle to 0 and end angle to 2*Math. PI. Tip: Use the stroke() or the fill() method to actually draw the arc on the canvas.


2 Answers

Yes, you should have a canvas that has a relative position to your pizza image. Then you can draw your circle on canvas, and configure canvas transparency

Read how to draw circles from here:

http://billmill.org/static/canvastutorial/ball.html

like image 167
batbaatar Avatar answered Oct 22 '22 09:10

batbaatar


You could try generating a SVG and then look into Clipping, Masking and Compositing

like image 21
Matthias Avatar answered Oct 22 '22 08:10

Matthias