# How to bulk convert SVG to PNG in the terminal

**URL:** <https://forum.codeselfstudy.com/t/how-to-bulk-convert-svg-to-png-in-the-terminal/1625>\
**Category:** Operating Systems, Editors, and Tools\
**Tags:** inkscape, design\
**Created:** [May 10, 2019, 10:52pm UTC](https://forum.codeselfstudy.com/t/how-to-bulk-convert-svg-to-png-in-the-terminal/1625 "2019-05-10T22:52:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/josh/32/4_2.png) [@Josh](https://forum.codeselfstudy.com/u/Josh)\
**Post date:** [May 10, 2019, 10:52pm UTC](https://forum.codeselfstudy.com/t/how-to-bulk-convert-svg-to-png-in-the-terminal/1625/1 "2019-05-10T22:52:26Z")

</div>

I just learned that Inkscape can convert from SVG to PNG at the command line:

```nohighlight
$ inkscape -z -e filename.png -w 300 -h 300 filename

```

This will bulk-convert an entire directory of SVG images to PNG:

```bash
for f in *.svg; do
   inkscape -z -e ${f:0:-4}.png -w 300 "$f"
done

```

(`${f:0:-4}.png` strips off the `.svg` extension and adds `.png`)

---

<div class="post-metadata">

**Author:** ![Dan](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/dan/32/4311_2.png) [@Dan](https://forum.codeselfstudy.com/u/Dan)\
**Post date:** [May 11, 2019, 5:31am UTC](https://forum.codeselfstudy.com/t/how-to-bulk-convert-svg-to-png-in-the-terminal/1625/2 "2019-05-11T05:31:39Z")

</div>

At first I thought this sounded like something ImageMagick could do as well, but after poking around a bit I saw where people have had trouble with this particular conversion in ImageMagick. The suggested work-around is often to just to use Inkscape instead.

---

<div class="post-metadata">

**Author:** ![Josh](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/josh/32/4_2.png) [@Josh](https://forum.codeselfstudy.com/u/Josh)\
**Post date:** [May 11, 2019, 5:54am UTC](https://forum.codeselfstudy.com/t/how-to-bulk-convert-svg-to-png-in-the-terminal/1625/3 "2019-05-11T05:54:56Z")

</div>

The conversion worked well for most of the images, but after looking through more of them, I saw that there was a problem with a few of them, even when opening them in Inkscape’s GUI. I’m not sure why it wasn’t rendering them correctly. Firefox and [KolourPaint](https://kde.org/applications/graphics/kolourpaint/) were rendering them. I wonder if the SVG images were using an SVG tag or feature that isn’t supported in Inkscape.

**Edit:** I don’t see anything unusual in the SVG source (the values were removed below to reduce the amount of text).

```auto
<svg xmlns="http://www.w3.org/2000/svg" width="" height="" viewBox="">
    <g transform="matrix()">
        <rect y="" x="" height="" width="" rx="" ry="" fill="#fff" stroke="#000" stroke-width="" />
        <path d="" />
    </g>
    <path d="" fill="" />
    <path d="" fill="" />
    <path d="" fill="" />
    <path d="" />
    <path d="" />
</svg>

```

---

<div class="post-metadata">

**Author:** ![Dan](https://forum.codeselfstudy.com/user_avatar/forum.codeselfstudy.com/dan/32/4311_2.png) [@Dan](https://forum.codeselfstudy.com/u/Dan)\
**Post date:** [May 11, 2019, 1:21pm UTC](https://forum.codeselfstudy.com/t/how-to-bulk-convert-svg-to-png-in-the-terminal/1625/4 "2019-05-11T13:21:27Z")

</div>

Interesting.
