php 网络图片转base64

/** 把网络图片图片转成base64
     * @param string $img 图片地址
     * @return string
     */
    /*网络图片转为base64编码*/
    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)));
    }

 

posted @ 2020-03-31 20:53  zhangPooo  阅读(254)  评论(0)    收藏  举报