php把网络图片转Base64编码。

Posted on 2018-12-07 17:41  jiaoqing。  阅读(4341)  评论(0)    收藏  举报

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

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3