
博客默认的Gravatar太煞风景?那就换了它!

前言
相信大部分做过网站的朋友都知道,Gravatar
是一个全球性的头像设置平台
除中国以外大部分网站都是调用的此平台头像,但因为我们伟大的祖国有一般人射不穿的城墙
所以用这个头像平台的用户很少,导致大部分使用此头像平台的网站
评论区总会有很多Gravatar
的官方默认头像
定位文件
↓我们会发现下面一段语句↓
<?php $comments->gravatar('40', ''); ?>

↓果断删掉↓
↓改成如下代码↓
<span itemprop="image">
<?php $number=$comments->mail; echo '<img src="https://q2.qlogo.cn/headimg_dl? bs='.$number.'&dst_uin='.$number.'&dst_uin='.$number.'&;dst_uin='.$number.'&spec=100&url_enc=0&referer=bu_interface&term_type=PC" width="46px" height="46px" style="border-radius: 50%;float: left;margin-top: 0px;margin-right: 10px;margin-bottom:-2px">'; ?>
</span>

总结
效果

更新
在通常情况下,当用户输入了QQ
邮箱,我们的头像才会调用为QQ
头像。但是假如用户使用的是163
邮箱或者是其它
邮箱,那么头像肯定会显示失败。那么该怎样解决这个问题呢?其实也很简单,我们放个if
判断语句就行了。先判断输入的邮箱是不是QQ
邮箱,如果是调用QQ
邮箱,如果不是则调用Gravatar
头像或者其他的静态头像,或者随机头像即可。
更新代码
<span itemprop="image">
<?php $number=$comments->mail;
if(preg_match('|^[1-9]\d{4,11}@qq\.com$|i',$number)){
echo '<img src="https://q2.qlogo.cn/headimg_dl? bs='.$number.'&dst_uin='.$number.'&dst_uin='.$number.'&;dst_uin='.$number.'&spec=100&url_enc=0&referer=bu_interface&term_type=PC" width="46px" height="46px" style="border-radius: 50%;float: left;margin-top: 0px;margin-right: 10px;margin-bottom:-2px">';
}
else
{
echo '<img src="https://bing.ioliu.cn/v1/rand?w=1920&h=1080" width="46px" height="46px" style="border-radius: 50%;float: left;margin-top: 0px;margin-right: 10px;margin-bottom:-2px">';
}
?>
</span>
整理的随机图片API接口
速度: ★★★★★
功能: 返回Bing的随机图片
地址:
https://uploadbeta.com/api/pictures/random/?key=BingEverydayWallpaperPicture
速度: ★★★★☆
功能: 来自github的项目https://github.com/xCss/bing
地址:
https://bing.ioliu.cn/v1/rand (返回随机图片)
https://bing.ioliu.cn/v1/rand?w=1920&h=1080 (指定大小)
本篇文章采用 署名 4.0 国际 (CC BY 4.0) 许可协议进行许可。
Hacther
Windows 10 / MicroSoft Edge
May 2nd, 2020 at 07:46 pm
牛逼就完事了~
回复
arrow_back
上一篇
arrow_forward
下一篇