简体   繁体   English

阿凡达麻烦圆角

[英]Avatar troubles rounded corners

I'm trying to figure out what's the best method to do the following: Let's say I have a circle with color x where I want to put an avatar in, my goal is to make the avatar image round too in order to make the result look a lot nicer. 我正在尝试找出执行以下操作的最佳方法:假设我有一个颜色为x的圆圈要放置化身,我的目标是也使化身图像变圆以产生结果看起来好多了。

I can do this with php-gd, but will have probably need to do a lot of calculations(unless I've missed out on some gd function), is there a better or faster way to tackle it eg css? 我可以用php-gd来做到这一点,但可能需要做很多计算(除非我错过了某些gd函数),有没有更好或更快速的方法来解决它,例如CSS?

tia tia

If I was you I would use CSS3 for simplicity. 如果我是你,我会使用CSS3来简化。 The below will turn the image into a circle and give it a 1px circle border. 下面将把图像变成一个圆圈,并给它一个1px的圆圈边框。

div.avatar{
    width:30px; height:30px; border:solid 1px #000;
    -webkit-border-radius: 16px; -moz-border-radius: 16px; border-radius: 16px;
}

div.avatar img{
    width:30px; height:30px;
    -webkit-border-radius: 15px; -moz-border-radius: 15px; border-radius: 15px;
}

<div class="avatar"><img src="" /></div>
  • CSS3 isnt supported by old versions of IE IE的旧版本不支持CSS3

Easiest would be using simple CSS selectors: 最简单的方法是使用简单的CSS选择器:

<img class="avatar" src="" />

and in your CSS file: 并在您的CSS文件中:

.avatar {
    border-radius: 50%;
}

Yup, it's that simple. 是的,就是这么简单。 Check out my Codepen example: http://codepen.io/usersnap/pen/udJgc 看看我的Codepen示例: http ://codepen.io/usersnap/pen/udJgc

You're actually better to use a bit of CSS trickery to do this. 实际上,您最好使用一些CSS技巧来做到这一点。 Basically you want to set up a transparent PNG positioned above the image, using it as a mask for the image. 基本上,您想设置一个位于图像上方的透明PNG,并将其用作图像的蒙版。 For an example check out this post about it . 例如, 查看有关此帖子

I wouldn't recommend using a CSS3 solution (border-radius) without some kind of backup, as it's much less supported. 我不建议您在没有某种备份的情况下使用CSS3解决方案(边界半径),因为它的支持要少得多。 But I guess if your okay with only having modern support then CSS3 would be the better option. 但是我想如果您只接受现代支持就可以了,那么CSS3将是更好的选择。

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

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