1<?PHP2 /**3 * processed into a circle picture, if the picture is not a square, take the smallest edge of the circle radius, from the left to cut into a circle4 * @param string $imgpath [description]5 * @return [Type] [description]6 */7 functionYuan_img ($imgpath= './code_png/share.jpg ') {8 $ext=PathInfo($imgpath);9 $src _img=NULL;Ten Switch($ext[' extension ']) { One Case' jpg ': A $src _img= Imagecreatefromjpeg ($imgpath); - Break; - Case' PNG ': the $src _img= Imagecreatefrompng ($imgpath); - Break; - } - $WH=getimagesize($imgpath); + $w=$WH[0]; - $h=$WH[1]; + $w=min($w,$h); A $h=$w; at $img= Imagecreatetruecolor ($w,$h); - //This sentence must have -Imagesavealpha ($img,true); - //pick a completely transparent color and the last parameter 127 is fully transparent - $BG= Imagecolorallocatealpha ($img, 255, 255, 255, 127); -Imagefill ($img, 0, 0,$BG); in $r=$w/2;//Circle Radius - $y _x=$r;//Center X coordinate to $y _y=$r;//Center Y coordinate + for($x= 0;$x<$w;$x++) { - for($y= 0;$y<$h;$y++) { the $rgbColor= Imagecolorat ($src _img,$x,$y); * if(((($x-$r) * ($x-$r) + ($y-$r) * ($y-$r)) < ($r*$r))) { $Imagesetpixel ($img,$x,$y,$rgbColor);Panax Notoginseng } - } the } + A return $img; the } + - Header("Content-type:image/png"); $Imagepng (Yuan_img ());
PHP GD Round chart-processing into a circle picture