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 'data:' . $imageInfo['mime'] . ';base64,' . 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('data:image/jpeg;base64,'+base64_data.decode('utf-8'))
os._exit(0)

发表回复