tp5圆形生成图片

浏览:1283 发布日期:2019/05/29 分类:技术分享 关键字: tp5圆形生成图片
function round() {

$w = $this->info['width'];
$h = $this->info['height'];
$w = min($w, $h);
$h = $w;
$img = imagecreatetruecolor($w, $h);
//这一句一定要有
imagesavealpha($img, true);
//拾取一个完全透明的颜色,最后一个参数127为全透明
$bg = imagecolorallocatealpha($img, 255, 255, 255, 127);
imagefill($img, 0, 0, $bg);
$r = $w / 2; //圆半径
$y_x = $r; //圆心X坐标
$y_y = $r; //圆心Y坐标
for ($x = 0; $x < $w; $x++) {
for ($y = 0; $y < $h; $y++) {
$rgbColor = imagecolorat($this->im, $x, $y);
if (((($x - $r) * ($x - $r) + ($y - $r) * ($y - $r)) < ($r * $r))) {
imagesetpixel($img, $x, $y, $rgbColor);
}
}
}
$this->im= $img;

return $this;
}

加入到 Image.php
调用
$result= $image->thumb($w,$h,\think\Image::THUMB_AUTO)->round()->save($temp_path."/".$image_name);
完毕
最佳答案
评论( 相关
后面还有条评论,点击查看>>