【发布时间】:2011-11-20 03:37:56
【问题描述】:
如何转换 svg 字符串
<svg>....<path>...</path>...</svg>
到 php 中的 png base64 编码字符串/文件?
【问题讨论】:
-
这是this question的副本。
-
This question 我认为是更接近的匹配项。
如何转换 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 );
}
}
【讨论】: