php5: convert svg to png base64 encoded
how can i convert a svg string
<svg>....<path>...</path>...</svg>
to a png base64 encoded 开发者_C百科string / file in php?
Take a look to svg2png library. Github project here.
An example of use:
data:image/svg+xml;base64, -> base64_encode()
Use this function
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 );
}
}
精彩评论