php裁剪透明圆形头像
作者:xlnxin发布时间:2023-08-05分类:其他教程浏览:668
导读:function image2circle($src, $dst){ //获取原图尺寸,并设置新图片的宽度和高...
function image2circle($src, $dst){
//获取原图尺寸,并设置新图片的宽度和高度
list($w, $h) = getimagesize($src);
if( $w > $h ){
$w = $h;
}else{
$h = $w;
}
$oimgSrc = imagecreatefromstring(file_get_contents($src));
$oimgDst = imagecreatetruecolor($w, $h);
imagealphablending($oimgDst,false);
$transparent = imagecolorallocatealpha($oimgDst, 0, 0, 0, 127);
$r=$w/2;
for($x=0;$x<$w;$x++){
for($y=0;$y<$h;$y++){
$c = imagecolorat($oimgSrc,$x,$y);
$_x = $x - $w/2;
$_y = $y - $h/2;
if((($_x*$_x) + ($_y*$_y)) < ($r*$r)){
imagesetpixel($oimgDst,$x,$y,$c);
}else{
imagesetpixel($oimgDst,$x,$y,$transparent);
}
}
}
imagesavealpha($oimgDst, true);
imagepng($oimgDst, $dst);
imagedestroy($oimgDst);
imagedestroy($oimgSrc);
}- 上一篇:php图片压缩
- 下一篇:微信小程序image mode属性显示图片对应的格式详解
- 其他教程排行
-
- 1抖音极速版给大家发37元过年红包啦,快来领取吧!
- 2统信uos系统默认root密码是多少
- 3admin、0000、admin888、123456 md5加密后16位和32位代码
- 4国产安可立思辰打印机手动双面打印设置教程
- 5Windows10 DVDRW识别为CD驱动解决方法,windows无法读取驱动器E:\中的光盘解决方法
- 6navicat premium 15破解版64位32位 v15.0.3激活方法
- 7小程序Cannot read property 'enableUpdateWxAppCode'解决方法
- 8快手极速版给大家发56元新年红包啦,快来领取吧!
- 9查找对话框跑出屏幕外看不见了,怎么拖回来?
- 最近发表

