如何转换 svg 字符串
<svg>....<path>...</path>...</svg>
到 php 中的 png base64 编码字符串/文件?
使用此功能
function svgToBase64 ($filepath){
if (file_exists($filepath)){
$filetype = pathinfo($filepath, PATHINFO_EXTENSION);
if ($filetype==='svg'){
$filetype .= '+xml';
}
$get_img = file_get_contents($filepath);
return 'data:image/' . $filetype . ';base64,' . base64_encode($get_img );
}
}