admin管理员组文章数量:1279083
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.
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.
Share Improve this question asked Jul 10, 2013 at 19:46 Lucas T.Lucas T. 1332 gold badges3 silver badges10 bronze badges 03 Answers
Reset to default 9Put 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*/
}
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>
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.
本文标签: javascriptTransform an image into a circleStack Overflow
版权声明:本文标题:javascript - Transform an image into a circle - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741224664a2361629.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论