笔记 · · 564 阅读

网络图片转Base64编码

base64
网络图片转Base64编码

1.PHP实现版 https://www.cnblogs.com/yyhhblog/p/10084163.html

/** 把网络图片图片转成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 [removed] . chunk_split(base64_encode(file_get_contents($img)));
    }

2.python实现版

import base64
res = requests.get("http://ptqwdkg68.bkt.clouddn.com/6e51922a8b9f98343a7f6493ed4e66b9_portrait")
base64_data = base64.b64encode(res.content)
# base64.b64decode(base64data)
print([removed]+base64_data.decode('utf-8'))
os._exit(0)
0 评论

评论

还没有评论,来说两句吧