Encapsulated PostScript (EPS) is the standard graphics format for many journals. Having just converted my figures to EPS, I want to share what I’ve learned. The short version: while at first the results look dreadful, with a little work, Scalable Vector Graphics (SVG) images can be converted into decent looking EPS files.
The reason you might have SVG figures in the first place is that you are using Inkscape rather than Adobe Illustrator (AI) to develop them. Unlike AI, Inkscape is unencumbered by Adobe software licensing restrictions, and you can use it on any mainstream operating system. It uses SVG format to store vector images, so if you are developing figures in Inkscape, you will eventually need to convert them to EPS format. For AI, this is less of a problem, because AI format is apparently a close cousin to EPS.
Variations on a Naïve Approach
The naïve approach is to export an EPS figure directly from Inkscape. For all but the simplest images, this doesn’t work. The result of this export is an image that mixes vector and rasterized components seemingly at random. This produces truly bizarre and ugly results. Some variations on the naïve approach that work equally well are: opening the SVG in Illustrator, copying and pasting from Inkscape to Illustrator, and saving as a Windows Metafile to open in Illustrator. To be clear, none of these variations produces remotely good results.
Why the Naïve Approach Fails
The naïve approach fails because EPS is not a very sophisticated file format. In particular, it has very poor support for transparency. Whenever I had a figure that used alpha at all, which is almost every figure, the EPS export turned out badly. This page on Adobe’s website seems to indicate that Illustrator does some proprietary magic to get decent transparency in EPS files. Whatever it is, Inkscape doesn’t do it, and I couldn’t find an automatic converter that did. In addition to Inkscape’s SVG to EPS converter, I tried ImageMagick and Scribus, neither of which did any better, and both of which found new ways to fail.
Rasterization (No! Not Rasterization!)
“No! Not rasterization!” was my first response when I realized that rasterization is by far the easiest way out. Rasterization is ugly. It gives you aliased lines and blurry fonts. And EPS is at least nominally a vector format, so rasterization is particularly painful because it ought not to be necessary. Here’s the obligatory illustration of how ugly rasterized text can be:
Also, rasterization gives you huge files! Here’s how EPS represents vector content:
4 M q 1 0 0 -0.477488 0 275.015381 cm 359.477 352.537 m 322.563 388.606 263.395 387.919 227.324 351.007 c 191.254 314.087 191.941 254.923 228.855 218.854 c 265.77 182.785 324.938 183.472 361.008 220.384 c 394.121 254.277 396.633 307.583 366.848 344.438 c S Q 363.973 108.851 m 365.199 112.59 l 371.363 110.211 l h 363.973 108.851 m f* 0.77053 w q -0.808223 -0.477488 -1 0.385917 0 275.015381 cm 32.558 -390.287 m 27.223 -387.201 l 27.223 -393.365 l h 32.558 -390.287 m S Q 1.368923 w 1 J q 1 0 0 -1 0 275.015381 cm 281.66 33.609 m 272.492 27.789 270.355 16.457 276.895 8.297 c 283.43
I don’t know EPS at all; this is just a sample of vector graphics look like in an EPS file. I’m pretty sure those are drawing commands. Anyway, compare with raster graphics:
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFFFFCFCFCFBEBDBDBDC0C0D3C4C6F6CFD3F4D3D7F8E3E5FAEBECFAE9EBF7DFE1 F1C3C8ECADB3E9A5ACEBABB1EAA3ABE89CA4E6979FE798A0E79AA3E89DA5E89CA4E697A0E5949C E5939BE6949DE796A0E89BA4E89BA4E698A0E5919AE5929BE89CA4EAA6ADEDB1B7EFBBC0F1C4C8 F2CACEF3CDD1F3CCD0F2C8CCF1C4C9F1C1C6F1C0C6F0C0C6F0C1C6F1C2C7F0C1C6F0BFC4EFB9BF ECAFB5ECB0B6EEB8BDEFBDC2EFBCC2EDB0B7EAA4ABE89FA7E698A1E698A0E89BA3E89FA7EAA4AB EAA7AEEAA6ACEAA6ADEAA6ADE99FA7E799A1E697A0E798A0E79AA2E89DA5E9A1A9EAA5ACEAA6AD EBA6ADEAA6ADE6969FE5919AE6949DE799A2E798A1E5919AE48C95E58F98E6949DE9A1A9EAA6AD EAA3ABE89DA5E5949DE5939BE799A1EAA6ADECAFB6EEB4BBEAA4ABE89FA7E799A1E69199E59099 E6949DE99FA7EBAAB2E9A3AAE79AA2E89BA3E9A0A8E9A2A9E89FA7E89DA5E89CA4E99DA6E9A0A8 EAA5ACEBA8B0E89CA4EBA9B0ECAFB5EBADB3EBACB2ECADB4EDB1B8EDB2B8EEB7BDF0BDC2F0BEC4 ECAFB6EAA5ACE89FA6CAB5B7BFC1C1BEC3C3CCABAEE4828CE2848DE48B95E6969EE89FA6EAA6AD EAA6AEEAA4ACE9A0A8E89DA5E89EA6E9A0A7E89EA6E799A2E799A2E89EA6EAA4ACEBA9B0ECACB3
Unlike the vector commands, I can tell you exactly what’s going on there, and it’s not pretty. Those are 8 bit RGB values in hexadecimal, represented with ASCII text (which means that they take up exactly twice as much space as they need to.) So one light grey pixel is, for example, ADADAD. And all those Fs? Empty white space. This is why high resolution bitmaps take up a ridiculous amount of space in EPS format.
So much for the case against rasterization. The case for it is simply that the alternative is much more work..
How to Rasterize an SVG
First, in Inkscape, make a new layer for your background. Put a big white rectangle in it, and lower this layer to the bottom of the layer stack. This step prevents the background from being filled in unpredictably.
Inkscape can export directly to raster formats. As I mentioned, it also exports to EPS, but that naïve route doesn’t work. Export your figure as a Portable Network Graphics (PNG) file. Use an embarrassingly large resolution. This is just an intermediate step, and you can always delete the PNG once you have your EPS. The PNG is compressed, so it will take up much less space than the EPS anyway. Next comes the part where you need another piece of free software. Get a copy of ImageMagick. Then use its convert utility to make an EPS from the PNG. For example,
convert -resize 50% simplex_schematic.png simplex_schematic.eps
Play around with the percentage by which you resize the figure. Be happy that in this modern era, nobody bats an eye at a four megabyte image file.
A Hybrid Approach
By understanding its limitations, we can make Inkscape’s EPS export work for us. Remember how I said Inkscape’s rasterization is unpredictable? We can make it more predictable by rasterizing part of the figure. If enough of the figure is already rasterized, Inkscape will leave the rest in vector form. My theory on what gets rasterized is as follows. Any vector content that has a property that EPS can’t handle, particularly transparency, gets rasterized. Also, any vector content that interacts with a property EPS can’t handle. So if you have text under a transparent overly, all of it gets rasterized, even if the text itself is opaque.
The basic hybrid approach is to separate all text in your figure into a separate layer, hide the text layer, and export the rest of the figure as a high-resolution bitmap. Then import the bitmap, line it up with the vector components it replaces, and hide the vector components of the figure other than text, so you have text overlaid on an opaque raster image. Finally export as an EPS. These actions improve the appearance of the figure considerably, since rasterized text looks dreadful.
This approach can be extended to non-text elements of your figure, if you have the patience for it. This works best for simple elements like arrows and axes, as long as they don’t have anything drawn over them. The point of diminishing returns arrives rapidly, however.
Inkscape is great. It’s free, and it’s easy to use. If, during the figure creation process, you’re careful about segregating the parts of your figure that force rasterization, you can enjoy the clean lines of vector graphics in your finished figure. Even if you don’t consider the EPS conversion until very late, picking the low-hanging fruit (text) is easy and dramatically improves the appearence of your figure.
Edit (4 February, 2013): A better explanation
See these threads on StackExchange: