# Converting image files to svg?

**URL:** https://discourse.julialang.org/t/converting-image-files-to-svg/35428
**Category:** General Usage
**Created:** [March 2, 2020, 8:34pm UTC](https://discourse.julialang.org/t/converting-image-files-to-svg/35428 "2020-03-02T20:34:41Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)
#### Post date: [March 2, 2020, 8:34pm UTC](https://discourse.julialang.org/t/converting-image-files-to-svg/35428/1 "2020-03-02T20:34:41Z")

</div>

Is there a way to convert image files to .svg? FileIO.jl seems to cover many of the file types I have (wmf, eps, png, bmp, bdf, etc.) with `load` and `save`. Any other package I can use? E.g., via `savefig` in `Plots`?

---

<div class="post-metadata">

### Author: ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)
#### Post date: [March 3, 2020, 3:34am UTC](https://discourse.julialang.org/t/converting-image-files-to-svg/35428/2 "2020-03-03T03:34:07Z")

</div>

My guess is no. I believe SVG is a vector format, meaning the “image” is a series of vectors. PNG, BMP, JPG, etc are bitmaps, i.e a each pixel has a color. Converting from pixels into vectors would be tricky and error prone. So you can probably go from SVG to the other image formats…but the reverse is no straight forward.

---

<div class="post-metadata">

### Author: ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)
#### Post date: [March 3, 2020, 7:42am UTC](https://discourse.julialang.org/t/converting-image-files-to-svg/35428/3 "2020-03-03T07:42:22Z")

</div>

Yes, SVG is a vector format. But SVG files can also contain bitmapped images. I can open many bitmapped image formats in Inkscape, and save them as SVG files.

The main reason I want to convert bitmapped images to SVG is that my word processor (LyX) seems to handle SVG files better than some of the other formats. [I recently imported some bitmapped images into LyX, and it didn’t read properly the size of the images → all images exceeded their boundaries into other images, way above the header, etc., and I had a major job to fix it.] So I was kind of thinking of using Julia to batch convert the files to SVG…

---

<div class="post-metadata">

### Author: ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)
#### Post date: [March 3, 2020, 8:08am UTC](https://discourse.julialang.org/t/converting-image-files-to-svg/35428/4 "2020-03-03T08:08:13Z")

</div>

Maybe just create wrapper .svg files, each containing a single `<image> ` tag? [\<image\> - SVG: Scalable Vector Graphics | MDN](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image)

This could be done with a simple `println` statement from Julia.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [March 3, 2020, 8:41am UTC](https://discourse.julialang.org/t/converting-image-files-to-svg/35428/5 "2020-03-03T08:41:53Z")

</div>

Even if you just want to embed a pixel image in an SVG, is there a specific reason you want to do this in Julia? There are many perfectly fine command line tools for these purposes, eg

> **[ImageMagick](https://en.wikipedia.org/wiki/ImageMagick)**
>
> ImageMagick, invoked from the command line as magick, is a free and open-source cross-platform software suite for displaying, creating, converting, modifying, and editing raster images. ImageMagick was created by John Cristy in 1987, it can read and write over 200 image file formats. It is widely used in open-source applications.
> ImageMagick was created in 1987 by John Cristy when working at DuPont, to convert 24-bit images (16 million colors) to 8-bit images (256 colors), so they could be di...

---

<div class="post-metadata">

### Author: ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)
#### Post date: [March 3, 2020, 10:00am UTC](https://discourse.julialang.org/t/converting-image-files-to-svg/35428/6 "2020-03-03T10:00:03Z")

</div>

> [@Tamas\_Papp](#):
>
> is there a specific reason you want to do this in Julia?

I guess it is the “dream” of a one-language-fits-all. In particular when I need to do batch conversion.

In this specific case, some figures were drawn in Visio, and saved as wmf, eps, pdf, etc. files to try to make the result look nice. Others are mobile phone pictures (bmp, png, etc.) of hand drawings meant for later drawing in Inkscape. Etc.

So I have multiple versions of each file. For some files, I even have svg files in addition to visio files, pdf files, etc. So I need to read all files. For file names where there already is an svg file, I don’t want to overwrite that file. For files where there is no svg file, I’d want to use a pdf file (or Visio file) if such exists. If only bitmap files exist, I’d make a ranking of which has best quality.

Anyway, I’ll take a look at ImageMagick – thanks for suggestion.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [March 3, 2020, 10:06am UTC](https://discourse.julialang.org/t/converting-image-files-to-svg/35428/7 "2020-03-03T10:06:37Z")

</div>

> [@BLI](#):
>
> the “dream” of a one-language-fits-all

I am not sure this is a reasonable expectation.

Converting images is a very special task yet well-defined task, so it may not make sense for all languages to develop code for all formats out there (and there are very many).

Tasks like this are not where Julia shines; you would just replace a one-liner (eg calling out to the shell) with another one-liner.

---

<div class="post-metadata">

### Author: ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)
#### Post date: [March 3, 2020, 10:11am UTC](https://discourse.julialang.org/t/converting-image-files-to-svg/35428/8 "2020-03-03T10:11:19Z")

</div>

You are probably right. I may take a look at PythonMagick.

---

<div class="post-metadata">

### Author: ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)
#### Post date: [March 3, 2020, 8:18pm UTC](https://discourse.julialang.org/t/converting-image-files-to-svg/35428/9 "2020-03-03T20:18:21Z")

</div>

Aha! `Plots` uses `ImageMagick` for loading. Maybe also for saving? The following works for me:

```julia
load("testimage.png") |> plot
savefig("testimage.svg")

```
