##### php将远程图片转换为base64
```php
getMessage();
}
}
/**
* curl请求
* @param $url string 远程图片地址
* @param $header array 请求头数据
* @param $timeout int 时间
* @param $refer
* @return bool|string
*/
function curl_post($url, $header, $timeout, $refer)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_REFERER, $refer);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //不验证证书下同
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); //
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
$data = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($code == 200) {
return "data:image/jpeg;base64," . base64_encode($data);
}
return false;
}
image_to_base64('https://cdn.fastadmin.net/uploads/addons/command.png!/fwfh/300x200');
```