php url圖轉base64編碼

    /**
     * 網絡圖轉base64編碼
     * @param  string  $img       圖片網址
     * @param  boolean $imgHtmlCode [description]
     * @return [type]               str
     */str
    public function imgtobase64($img='', $imgHtmlCode=true)
    {
        $imageInfo = getimagesize($img);
        $base64 = "" . chunk_split(base64_encode(file_get_contents($img)));
        return 'data:' . $imageInfo['mime'] . ';base64,' . chunk_split(base64_encode(file_get_contents($img)));;
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章