0

I'm having issues to export a SVG code to JPG with PHP and Imagick, because it contains the tag 'textpath'. The complete SVG is:

<svg id="svg_export" viewBox="0 0 800 533 " style=" pointer-events: none;">
<svg xmlns="http://www.w3.org/2000/svg" width="800" height="533" version="1.1">
    <svg id="svg-tree">
        <svg id="tree_title">

            <path id="path_title" d="M 282 478 q 120 20 240 0" stroke="blue" stroke-width="1" fill="none"></path>

            <text class="tspan_title_tree" style="font-size: 20px; font-family: Times;">
                <textPath id="text_title_svg" startOffset="50%" href="#path_title">Título</textPath>
            </text>
        </svg>
        <svg id="cell_1" x="381" y="432" height="31" width="41">
            <text id="text_cell_1" font-size="7" x="50%" alignment-baseline="middle" y="10.640625">
                <tspan class="tspan_cell_tree" x="50%" dy="1.2em" font-family="Times" style="font-family: Times;">
                    Plain Text
                </tspan>
            </text>
        </svg>
    </svg>
</svg>

The code I am using to export the image is:

    $im_cells = new \Imagick();
    $im_cells->setBackgroundColor(new \ImagickPixel('transparent'));
    $svg = $this->svgScale($this->svg, $width, $height);

    $im_cells->readImageBlob($svg);
    $im_cells->scaleImage($width, 0);
    $im_cells->setImageFormat("png32");

    $tree = new \Imagick($this->getBackgroundFile());
    $tree->scaleImage($width, 0);

    $result = new \Imagick();
    $result->newImage($width, $height, new \ImagickPixel('red'), 'png');

    $result->addImage($tree);
    $result->addImage($im_cells);
    $result = $result->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);

    $result->writeImage(base_path('orders/image.jpg"));

Once it is exported it only shows the curved line, without the text. I've read that imagick doesn't support this tag, so is there any way to do this?

I'd need to do it with this tool because in the process I overlay different layers, but if there are other ways please tell me, it will be helpful.

I've also tried to install Inkscape, but now any text is visible.

Thanks in advance!

Sònia
  • 13
  • 4
  • Can you post your full SVG file so we can test it. Imagick uses ImageMagick which has several possible renderers for SVG: its internal MSVG/XML, the RSVG delegate and Inkscape in order of better results. What does convert -list format show for SVG? If possible install Inkscape and ImageMagick will use that. – fmw42 Sep 07 '18 at 16:58
  • I've tried installing Inkscape but now any text is rendered (neither plain texts nor textpath). What convert -list format shows is: Scalable Vector Graphics (RSVG 2.40.13). I'm gonna edit the question to show the full SVG code. – Sònia Sep 07 '18 at 18:38
  • This may be helpful: [Convert SVG image to PNG with PHP](https://stackoverflow.com/questions/4809194/convert-svg-image-to-png-with-php) – enxaneta Sep 07 '18 at 18:55
  • `@Sònia`. Your SVG renderer is the RSVG delegate. Supposedly Inkscape should be better. What is your version of ImageMagick and what platform? I tried converting your SVG file to PNG on ImageMagick 6.9.10.11 Q16 Mac OSX with librsvg @2.42.2_1, but all I got was a completely white image. – fmw42 Sep 07 '18 at 20:24
  • I've tried to install Inkscape but I'm working in a shared hosting and I can't. I did it in my local machine but it only shows the path without the text. Finally I've decided to export the text without path, horizontally. However, thanks to all of you! – Sònia Sep 11 '18 at 09:35

1 Answers1

0

I installed Inkscape 0.92.3_4 on my Mac OSX Sierra with ImageMagick 6.9.10.11 Q16. I ran the following command:

convert -density 300 test.svg test.jpg

The resulting image shows a smile and some blurry text.

enter image description here

fmw42
  • 46,825
  • 10
  • 62
  • 80
  • That's the same it shows to me, but I need also the text over the path, and it doesn't appear. I don't know if it's due to the style (css) of the element or its properties. Thank you! – Sònia Sep 11 '18 at 09:36