meyfa / php-svg

Vector graphics (SVG) library for PHP
https://packagist.org/packages/meyfa/php-svg
MIT License
509 stars 91 forks source link

SVGTextPath node not being rasterized when added as child of SVGText #213

Closed liamjt95 closed 8 months ago

liamjt95 commented 9 months ago

Description

I'm trying to create an SVG image that contains some curved text. Exporting my document as XML results in a successful SVG that looks correct.

<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="236.05" height="78.86"
     viewBox="98.48 265.39 236.05 78.86" style="fill: none">
    <path d="M 99.97623748074814 266.88704311777553 C 119.74920068227658 314.6231990472097 166.33075715003895 345.74800000000005 218 345.74800000000005 C 269.66924284996105 345.74800000000005 316.2507993177234 314.62319904720965 336.0237625192519 266.8870431177755"
          id="text-path" style="fill: none; stroke: none"/>
    <text x="0" y="0" style="fill: #04ADB2; font-size: 40; font-weight: 400; text-anchor: middle; ">

        <!-- Problem is here, as 'textPath' is a child node of 'text' -->
        <textPath href="#text-path" style="text-anchor: 'middle';" startOffset="50%">Test Text</textPath>

    </text>
</svg>

My issue is that I now want to export this to a PNG with some custom font files I have installed locally. When rasterizing my image, I cannot see that the SVGTextPath node is being rendered at all. Looking at the code, it seems there is no logic in either \SVG\Nodes\Texts\SVGText::rasterize to rasterize children or any logic in \SVG\Nodes\Texts\SVGTextPath::rasterize.

Just want to check if I am missing some implementation detail or whether rasterizing child text nodes/text path nodes has not been implemented yet (I'm aware this stuff is a work in progress!).

Thanks!

Niellles commented 8 months ago

Looks like this was never implemented to me.

TextPath as a node was added in https://github.com/meyfa/php-svg/pull/42 , however, as you noted, without rasterization.

I don't want to speak for @meyfa, however I don't suspect this will be added soon, unless someone is willing to raise a PR. Your best bet, if you really need this, is probably to rasterize with Gmagick/Imagick.. or.. even better.. help fixing https://github.com/meyfa/php-svg/issues/98.

Niellles commented 8 months ago

For more discussion, also see: https://github.com/meyfa/php-svg/issues/10.

Voting to close this is a duplicate.

meyfa commented 8 months ago

Agreed, #10 covers all text elements, including <textPath>. Text rasterization is notoriously difficult with GD and placing text on paths even more so. Someone needs to dedicate some time to implement this - I'll gladly review PRs. Thanks for the opening this issue, but closing as a duplicate.

liamjt95 commented 8 months ago

Thanks for your responses! Unfortunately, this was required for some paid client work, for which we had to find another workaround. If I'm ever back in this space I will look into raising a PR.