php GD 圓圖 -處理成圓圖片

來源:互聯網
上載者:User

標籤:switch   最小   type   fill   src   func   share   col   pix   

 1 <?php 2  /** 3  * 處理成圓圖片,如果圖片不是正方形就取最小邊的圓半徑,從左邊開始剪下成圓形 4  * @param  string $imgpath [description] 5  * @return [type]          [description] 6  */ 7     function yuan_img($imgpath = ‘./code_png/share.jpg‘) { 8         $ext     = pathinfo($imgpath); 9         $src_img = null;10         switch ($ext[‘extension‘]) {11             case ‘jpg‘:12                 $src_img = imagecreatefromjpeg($imgpath);13                 break;14             case ‘png‘:15                 $src_img = imagecreatefrompng($imgpath);16                 break;17         }18         $wh  = getimagesize($imgpath);19         $w   = $wh[0];20         $h   = $wh[1];21         $w   = min($w, $h);22         $h   = $w;23         $img = imagecreatetruecolor($w, $h);24         //這一句一定要有25         imagesavealpha($img, true);26         //拾取一個完全透明的顏色,最後一個參數127為全透明27         $bg = imagecolorallocatealpha($img, 255, 255, 255, 127);28         imagefill($img, 0, 0, $bg);29         $r   = $w / 2; //圓半徑30         $y_x = $r; //圓心X座標31         $y_y = $r; //圓心Y座標32         for ($x = 0; $x < $w; $x++) {33             for ($y = 0; $y < $h; $y++) {34                 $rgbColor = imagecolorat($src_img, $x, $y);35                 if (((($x - $r) * ($x - $r) + ($y - $r) * ($y - $r)) < ($r * $r))) {36                     imagesetpixel($img, $x, $y, $rgbColor);37                 }38             }39         }40 41         return $img;42 }43 44 Header("Content-Type: image/png");45 imagepng(yuan_img());

 

php GD 圓圖 -處理成圓圖片

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.