The interesting workaround found by Puneet doesn't really solve the problem mentioned:
- let's have an svg A embedded into another svg file B.svg
- convert B into another format - let's say png- using Imagick
- A is not processed and not shown in the converted file B.png
This is a problem, expecially if your purpose is slightly different: for example if you need to convert your SVG into a PostScript file in order to send it to a printer, the solution mentioned by Puneet doesn't work.
Lets analyze the problem:
Imagick doesn't convert just the embedded svg.
I tried using Gmagick, another library used by big companies. No way.
I tried using the "convert" command line tool (I'm in a Debian 8 environment).
convert withNestedSvgTag.svg withNestedSvgTag.ps
No way.
It seems that the parser that parses the SVG file ignores completely the nested <svg>
tags, accepting only the root <svg>
tag.
I have another server, (Debian 7 and Imagick 3.1.0RC1), and it works like a sharm.
The other server seems rendering recursively each svg nested tag.
This means that the problem isn't the SVG file or the PHP code (consider that the Imagick class library simply wraps Imagemagick).
So, in conclusion, the real solutions are:
1.1 - Amend the Imagemagick code (I'll write to the community of developers reporting the problem in the bug section)
1.2 - Substituting the tag with another one, like the tag.
The 1.2 is another workaround, I know, but it seems working, obviously you have to set up properly the size of the elements in the group tag.