1

I'm trying to convert a "squared" image to a circle one.
The image is 48x48,its borders are squared.

I want to crop it with HTML/Javascript/CSS,to turn it into a circle.

0

3 Answers 3

9

Put that image as a div's background-image then set the border-radius of the div to 50%. Simple is that. :)

Fiddle.

CSS of the div:

div {
    width: 48px;
    height: 48px;
    background: url(your_image_url.your_image_extension);
    border-radius: 50%; /*the magic*/
}
1
  • Oooh sweeet!Thanks Mohammad! I just used "border-radius: 50%" and it worked great ;) It wasn't necessary to put the image as background-image.
    – Lucas T.
    Commented Jul 10, 2013 at 20:05
2

If you want to use just javascript this would work:

<img src='.../images/myImage.png' id="id">
<script>
document.getElementById('id').style.borderRadius = '50%';
</script>
0

Another way is to put the image into an editor and then cut the corners of the squares. Therefore, the part you don't want needs to be transparent. When you will put it in a webpage, the transparent part will inherit the color from behind.

8
  • i would go with this approach because border-radius is not supported in earlier versions of IE Commented Jul 10, 2013 at 19:50
  • 1
    Right, but the OP wanted an HTML/JS/CSS solution. Commented Jul 10, 2013 at 19:52
  • 2
    @DanyKhalife for css3 support in IE you could try this => github.com/lojjic/PIE Commented Jul 10, 2013 at 19:52
  • @ConstableJoe yup i agree, but im just pointing out that i think this is better :) Commented Jul 10, 2013 at 19:53
  • Not wanting to rain on anyone's parade, but those earlier versions of IE, aren't those the same versions that had troubles with transparency in PNG files? Of course, the OP never said the picture wasn't a GIF...
    – Mr Lister
    Commented Jul 10, 2013 at 20:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.