Generally trying to create an svg sprite using the npm svg-sprite package. As a result, I get something like this sprite (for 2 pictures):

... <svg viewBox="0 0 108 54" ...> <svg height="54" width="54" viewBox="-2 -2 54 54" ...> <path d="...”> </svg> <svg height="54" width="54" viewBox="-2 -2 54 54" ...> <path d="...”> </svg> </svg> 

To determine the size of the output sprite in CLI, I use the identify command from the ImageMagick utility. For example, so

identify -format '%w' icons-test.svg

or immediately write to the file

echo "\$spriteWidth = $(identify -format '%w' icons-test.svg)px" >> styles.styl

The problem is that as a result, the width of the entire sprite (108) is not recorded in the file, but only the last image included in it (54).

Tell me what I'm doing wrong, how to fix it? Or advise an alternative way to solve the problem.

    1 answer 1

    Presumably, the imagemagick SVG decoder does not understand some internal SVG tags. They advised to convert the file to another format, for example:

     convert icons-test.svg mvg:- | identify -format '%w' mv 

    For me, it worked. Sometimes, however, errors like these appear:

     identify: non-conforming drawing primitive definition 64' @ error/draw.c/RenderMVGContent/4361. 

    But still the width / height is determined correctly.

    So I note, as a decision. But if someone knows what caused / how to get rid of errors - write. Or if someone knows alternative solutions, too.