Images come in a variety of file types: jpg, png, pdf, eps, svg, tif, bmp, and countless other lesser-known ones. Each have their pros and cons, but they can be divided into two types: vector and raster. In science, we generally want vector images, unless we are dealing with photos.
A vector image saves lines as lines, text as text, polygons as polygons, etc. A raster image just saves all that data as a collection of coloured pixels. Vector images tend to have small file sizes and reproduce well on screen and in print because they have no inherent resolution. For example, compare the difference between zoomed versions of vector and raster images for a simple icon:
The vector image, being sharp and crisp, is much nicer to look at.
Which formats are vector?
These days, there are only four image types you should need to use: svg, pdf, jpg and png.
The diagram shows two other formats: eps and tiff. These were common many years ago, but not anymore as they’ve been superceded. In 2013, I was asked by a publisher to provide my figures in eps format. Maybe they were just behind the times, but it shows that it’s good to be aware of this legacy format. Same goes for tiff.
Raster images are often compressed to make the file size smaller. An important classification related to this is whether the compression is lossy or lossless. More information is given in the following section.
What’s the purpose of each?
svg–scalable vector graphics
This is a relatively new format and can be displayed on most web browsers with varying degrees of success depending on the complexity of the image. This is the format used by Inkscape, which you already know about right? If not, Learn Inkscape.
pdf–portable document format
You likely know pdfs as the format for multi-page documents. But you can just as easily create a single-page pdf of any dimension you like. Embedded within a pdf are the subset of the fonts it uses to ensure exact reproduction, i.e., no missing symbols or funny alignment problems you may get with svg.
I export images to pdf wherever possible. As an added bonus, they integrate easily with LaTeX.
jpg/jpeg–joint photographic experts group
This is the perfect format for photos as it takes up an incredibly small amount of space for what it holds. (A lot of fancy mathematics goes into the conversion of an image to a jpeg.) However, that’s all jpeg is good for. They are not a good choice for scientific figures because they smooth sharp lines and can produce artifacts, which are essentially unexpected changes in individual pixels.
png–portable network graphics
Sometimes vector graphics are not an option or simply raster images are a more reliable choice (such as images for webpages). If so, png should be your first choice unless your working with photos. png files are lossless, meaning no artifacts are produced. If exported with sufficient resolution (≥300 dpi), then they will reproduce nicely on screen and on paper. Note, though, that lossless is somewhat of a misnomer. Lots of information is still lost when a vector image is rasterised to a png.
Export figures to pdf where possible, and choose png over jpg unless working with photographs
One thought on “Know your image file formats”
Comments are closed.