简体   繁体   English

将图像转换成圆形

[英]Transform an image into a circle

I'm trying to convert a "squared" image to a circle one. 我正在尝试将“平方”图像转换为圆形图像。
The image is 48x48,its borders are squared. 图片为48x48,边框为正方形。

I want to crop it with HTML/Javascript/CSS,to turn it into a circle. 我想用HTML / Javascript / CSS裁剪它,使其变成一个圆圈。

Put that image as a div's background-image then set the border-radius of the div to 50% . 将该图像作为div的background-image然后将div的border-radius设置为50% Simple is that. 很简单。 :) :)

Fiddle. 小提琴。

CSS of the div: div的CSS:

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: 如果您只想使用JavaScript,则可以使用:

<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. 当您将其放在网页中时,透明部分将从后面继承颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM