Introducton
When I am asked to analyze data for collaborative research, I always send result images or graphs in vector formats so that some properties, such as colors and fonts, can be changed later. Charts exported from R are saved in EPS format, and figures output from my own programs are usually saved in SVG format.
However, there are many people who want to create figures using PowerPoint. For these researchers, I know that EPS and SVG are bad choices, and WMF/EMF is the best format to share. R can output graphs in WMF/EMF format, but not all of the programs I use support WMF/EMF output. So sometimes I have to convert the image format. In this case, I always use Inkscape to do the conversion.
Since I was recently asked to teach how to do this, I made a Google Colab notebook to convert vector images and uploaded it here to share the methods. I will briefly introduce the commands used in the notebook.
What is Inkscape?
For those who don't know the nice application, here is a brief introduction.
It is a free software that allows us to work on design and illustration with intuitive and easy-to-understand operation, just like Adobe Illustrator. Please see the official site for deteials.
How to do the conversion
First, install Inkscape if you do not have it yet. Google Colab is working on Ubuntu-based system, so the "apt" command is described below. Of course, Installation packages for other Linux distributions, MAC OS, or Windows OS are also available from the official site.
sudo apt-get install -y inkscape
Then all you need to do is run the Inkscape commands listed below, depending on the format you want to convert to.
Supported source image formats include AI (Adobe Illustrator), EPS, PDF, SVG, etc.
- ### To WMF
# Recent Inkscape (> ver. 1.0)
inkscape --export-filename=<path-to-output(.wmf)> <path-to-source-image>
# Old Inkscape
inkscape --without-gui --export-wmf=<path-to-output(.wmf)> <path-to-source-image>
- ### To EMF
# Recent Inkscape (> ver. 1.0)
inkscape --export-filename=<path-to-output(.emf)> <path-to-source-image>
# Old Inkscape
inkscape --without-gui --export-emf=<path-to-output(.emf)> <path-to-source-image>
- ### To PDF
# Recent Inkscape (> ver. 1.0)
inkscape --export-filename=<path-to-output(.pdf)> <path-to-source-image>
# Old Inkscape
inkscape --without-gui --export-pdf=<path-to-output(.pdf)> <path-to-source-image>
- ### To EPS
# Recent Inkscape (> ver. 1.0)
inkscape --export-text-to-path --export-filename=<path-to-output(.eps)> <path-to-source-image>
# Old Inkscape
inkscape --without-gui --export-ps-level=3 --export-text-to-path --export-eps=<path-to-output(.eps)> <path-to-source-image>
- ### To SVG
# Version independent
inkscape --export-plain-svg=<path-to-output(.svg)> <path-to-source-image>
You can also convert to the raster image format.
- ### To PNG
# To the white background image
inkscape --export-background=white --export-filename=<path-to-output(.png)> <path-to-source-image>
# To the transparent image
inkscape --export-background-opacity=0.0 --export-filename=<path-to-output(.png)> <path-to-source-image>
# To convert using old Inkscape, replace the '--export-filename'to'--export-png'.
As you can see, if you are using the latest version of Inkscape, the command is very simple. You just set the extension of the output file path to the format you want to convert to. When converting to EPS, the text is encoded as a path object to avoid garbling.
Conclusion
I introduced the methods to convert vector imgae using Inkscape. All the commands are available in my Google Colab Notebook.
Reference
Wiki for Inkscape command options.
Top comments (0)