PHP GD Round chart-processing into a circle picture

Source: Internet
Author: User
Tags transparent color

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.