溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

TP圖片怎么處理類添加圖片橢圓處理

發(fā)布時間:2021-07-02 16:42:15 來源:億速云 閱讀:158 作者:chen 欄目:大數據

本篇內容介紹了“TP圖片怎么處理類添加圖片橢圓處理”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

/**
     * 處理圓角圖片
     * @param  integer $radius  圓角半徑長度默認為50,處理成圓型
     */
    public function radius($radius = 50) {
        // $wh = getimagesize($imgpath);
        $w = $this->width();
        $h = $this->height();
        // $radius = $radius == 0 ? (min($w, $h) / 2) : $radius;
        $img = imagecreatetruecolor($w, $h);
        //這一句一定要有
        imagesavealpha($img, true);
        //拾取一個完全透明的顏色,最后一個參數127為全透明
        $bg = imagecolorallocatealpha($img, 255, 255, 255, 127);
        imagefill($img, 0, 0, $bg);
        $r = $radius; //圓 角半徑
        for ($x = 0; $x < $w; $x++) {
            for ($y = 0; $y < $h; $y++) {
                $rgbColor = imagecolorat($this->im, $x, $y);
                if (($x >= $radius && $x <= ($w - $radius)) || ($y >= $radius && $y <= ($h - $radius))) {
                    //不在四角的范圍內,直接畫
                    imagesetpixel($img, $x, $y, $rgbColor);
                } else {
                    //在四角的范圍內選擇畫
                    //上左
                    $y_x = $r; //圓心X坐標
                    $y_y = $r; //圓心Y坐標
                    if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
                        imagesetpixel($img, $x, $y, $rgbColor);
                        continue;
                    }
                    //上右
                    $y_x = $w - $r; //圓心X坐標
                    $y_y = $r; //圓心Y坐標
                    if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
                        imagesetpixel($img, $x, $y, $rgbColor);
                        continue;
                    }
                    //下左
                    $y_x = $r; //圓心X坐標
                    $y_y = $h - $r; //圓心Y坐標
                    if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
                        imagesetpixel($img, $x, $y, $rgbColor);
                        continue;
                    }
                    //下右
                    $y_x = $w - $r; //圓心X坐標
                    $y_y = $h - $r; //圓心Y坐標
                    if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
                        imagesetpixel($img, $x, $y, $rgbColor);
                        continue;
                    }
                }
            }
        }
        $this->im = $img;
        return $this;
    }

將以下代碼拷貝至圖片處理類文件中。

“TP圖片怎么處理類添加圖片橢圓處理”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI