PHP 图片转Base64的方法分享
//图片转base64
function image_to_base(){
$imagePath = 'https://image.jewelryhunt.net/zhaowu/20240126/3fa44222f4ac2fa59b55116dc32493131.png';
$img_type = substr($imagePath, -3);
// 读取图片文件内容
$imageData = file_get_contents($imagePath);
$file_content = base64_encode($imageData); // base64编码
$img_base64 = 'data:image/' . $img_type . ';base64,' . $file_content;//合成图片base64编码
return $img_base64;
}