How to convert text to SVG paths?

后端 未结 6 1885
孤街浪徒
孤街浪徒 2020-11-29 17:52

I have a font in ttf file and want to generate SVG with text turned into paths. I don\'t need image (so using imagettftext or Image Magick font rendering capabilities is not

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 18:44

    I just wrote a PHP library based on yours that manipulates font data (from SVG file) and does any sort of transformation on it. You may give it a try from the GitHub :

    https://github.com/kartsims/easysvg

    Usage example :

    require 'easySVG.php';
    $svg = new EasySVG();
    $svg->setFont("paris-bold-webfont.svg", 100, "#000000");
    $svg->addText("Simple text display");
    $svg->addAttribute("width", "800px");
    $svg->addAttribute("height", "100px");
    echo $svg->asXML();
    

    SVG data manipulation example :

    $def = 'YOUR SVG DEFINITION HERE';
    $easySVG = new EasySVG();
    // rotate by 40°
    $rotated_def = $easySVG->defRotate($def, 40)
    // rotate by 40° with center at (200,100)
    $rotated_def2 = $easySVG->defRotate($def, 40, 200, 100)
    // scale transform : width*4
    $scaled_def = $easySVG->defScale($def, 4)
    

提交回复
热议问题