<?php

function smarty_function_svgToBase64($params, &$smarty)
{
    if (file_exists($params['url']) && mime_content_type($params['url']) == 'image/svg+xml') {
        $svgContent = file_get_contents($params['url']);
        $base64 = base64_encode($svgContent);

        $result = 'data:image/svg+xml;base64,'.$base64;
    } else {
        $result = false;
    }

    if (!empty($params['assign'])) {
        $smarty->assign($params['assign'], $result);
    } else {
        return $result;
    }
}
