php5:将 svg 转换为 png base64 编码[重复]

问题描述 投票:0回答:1

如何转换 svg 字符串

<svg>....<path>...</path>...</svg>

到 php 中的 png base64 编码字符串/文件?

php svg png base64
1个回答
1
投票

使用此功能

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 );
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.