B
B
bjorn-mozyakin2019-02-12 01:16:55
css
bjorn-mozyakin, 2019-02-12 01:16:55

How can I determine the height/width of an svg sprite and write it to a file (via CLI on Mac or Linux)?

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

…
<svg viewBox="0 0 <b>108 54</b>" …>
  <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 the CLI, I use the identify command from the ImageMagick utility . For example, like this
identify -format '%w' icons-test.svg
or immediately write to a file
echo "\$spriteWidth = $(identify -format ‘%w’ icons-test.svg)px" >> styles.styl

The problem is that as a result, the width of not the entire sprite (108) is written to the file, but only the width of the last image included in it (54).
Tell me what I'm doing wrong, how to fix it? Or suggest an alternative way to solve the problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bjorn-mozyakin @, 2019-02-18
@bjorn-mozyakin

Presumably imagemagick's SVG decoder doesn't understand some internal SVG tags.
It was advised to first convert the file to another format, for example like this:
For me it worked. Sometimes, though, errors like this are thrown:
But all the same width/height are defined correctly.
So I'll mark it as a solution. But if someone knows what caused / how to get rid of errors - write. Or if someone knows alternative solutions - too.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question