5

I always prefer to keep my images in my library in vector form, so that they can be easily modified or scaled later if needed. However, when I am actually using these pictures in a LaTeX documented, a question arises if there is any need for vector graphics, when they can be replaced by high-resolution lossless raster pictures several times smaller in size? For instance, compare this vector picture saved in .pdf format (147 Kb) with the same high-resolution (1498 x 1498) losslessly compressed .png picture (8.31 Kb): A .png picture

As you see, the difference in picture sizes is nearly 10 times. And the image is pretty simple.

I believe you will not see the difference in the printed document, and you will never really scale the computer version to the point when you see separate pixels.

So is there a point in using larger vector graphics instead of compact raster pictures in LaTeX documents? I don't talk about cases, when vector graphics actually occupies less space than raster (is it so often, by the way?).

P.S. When reading professionally prepared scientific articles, one often encounters vector pictures. If articles get bigger this way, why would the professionals use them?

  • It depends partly on the distribution mechanism, if it's only paper, and the bitmap is sufficient resolution then the difference is essentially gone, but if you are distributing pdf, then the scalable format always has the benefit of being scalable. – David Carlisle Apr 02 '15 at 20:15
  • @DavidCarlisle Yes, but that's exactly the question. This raster image can be scaled to the whole page size, without the pixels being seen. So are there really a lot of situations when a reader will notice the difference if you suppose normal reading process? – Dr_Zaszuś Apr 02 '15 at 20:18
  • Your graphic has only straight lines. Try the same with curves. The difference between e.g. vector fonts and "raster" fonts is very noticable as the questions about fuzzy fonts shows. – Ulrike Fischer Apr 02 '15 at 20:38
  • 6
    A 147 Kb vector graphic representing that image is woefully inefficient. – Ian Thompson Apr 02 '15 at 20:40
  • @IanThompson Do you know a way to make it smaller? – Dr_Zaszuś Apr 02 '15 at 20:43
  • @UlrikeFischer Agreed. But scientific drawings often have straight lines... – Dr_Zaszuś Apr 02 '15 at 20:43
  • 2
    @Szczypawka: This image should ideally only consist of 43 objects: 42 grid lines, and the green polygon. The PDF you linked to consists of 400 different objects, which include a lot or redundant information (each grid line is drawn four times, for example). I recreated your image in Inkscape and saved it as a PDF: It takes up only 1.47 kB http://we.tl/yIhVchD8aQ – Jake Apr 02 '15 at 20:52
  • 3
    @Jake --- that beats my 2.9K xfig version! I think the original file was created by Adobe Illustrator, which is the work of Satan. – Ian Thompson Apr 02 '15 at 20:54
  • 1
    OTOH, really high resolution images (inserted in a PDF) take a long time to download. – John Kormylo Apr 02 '15 at 20:57
  • 1
    @Jake I believe the two of you have found the reasons of my large vector graphics. Yes, the 400 objects were in fact the 400 small squares: I was not thinking optimization when drawing (partly because I didn't have the finished concept when I started). And yes, the picture was created in Illustrator. I never thought that the difference in size would be that big. What does it put in there? – Dr_Zaszuś Apr 02 '15 at 21:26
  • @IanThompson See above – Dr_Zaszuś Apr 02 '15 at 21:26
  • When saving files from Illustrator you can specify in the save dialog unter "Adobe PDF Preset" to use "Smallest File Size". Use this for the files that go into production but keep another copy for editing. – Christian Lindig Apr 03 '15 at 08:29
  • @ChristianLindig Yes, but actually my question is not how to make my .pdf smaller, but whether one needs vector graphics (if they are larger) in a document intended for normal reading. Even if you manage to make this particular .pdf smaller, I am sure one can find those which will be larger than raster pictures. – Dr_Zaszuś Apr 03 '15 at 10:48
  • 1
    I'd strongly to suggest to embed vector graphics because it retains more information and use post-processing to reduce file size on a per-case basis. Resolution is only going up and maybe some day you want to create a poster from a page. – Christian Lindig Apr 03 '15 at 11:30
  • @Szczypawka --- Some complex images (e.g. shaded contour plots with large numbers of different regions) can be difficult to represent as vector graphics, and in those cases bitmaps may work better. However, for an image such as yours, a (decent) vector representation will give better quality and smaller size. There is no need to use a vector representation, but then there is no need to use LaTeX. You can write your document in Word and draw your diagrams using Paint. – Ian Thompson Apr 03 '15 at 11:47
  • 3
    I'm voting to close this question as off-topic because it asks about the use of vector graphics in PDF compared to bitmap graphics in PDF, which is not related to TeX. – Martin Schröder Apr 03 '15 at 13:10
  • @MartinSchroder You have the right to have your understanding of the question, but is actually about whether one needs vector graphics in LaTeX documents at all, when they do not give you advantage in space. I am not discussing pdfs in general, because it is the final way of using the pdf, which defines the type of graphics you will use. For instance, the advantages of using vector graphics in graphical design are evident, but what are they in a scientific report? – Dr_Zaszuś Apr 03 '15 at 16:35
  • People here on SO are sometimes too fast with closing questions... – Dr_Zaszuś Apr 03 '15 at 16:37
  • A compressed version of your PDF takes 40kB, a compressed version of the converted SVG takes 16kB. Unless all your images look like this is a bad sample of what to expect in general. Besides, with some imagination, this same figure should take 50 Bytes in a black and white BMP (ok, may be 400 Bytes counting the header), would you consider BMP as the format? – alfC Apr 03 '15 at 21:28
  • Even if in the screen they look the same, the printed version can show differences. – alfC Apr 03 '15 at 23:35

3 Answers3

5

For some complex images such as contour plots with very large numbers of differently shaded regions, bitmap formats may work better than vector formats. However, vector formats are always better for simple images consisting of a few lines and polygons.

Now vector formats use sequences of geometrical instructions to tell the computer how to construct the image. This is unlikely to be done in an optimal way, but the inefficiencies caused by programs such as gnuplot and xfig are rarely worth worrying about. Mostly they are caused by redundant definitions at the top of the file, amounting to a few kilobytes. However, Illustrator is notorious for filling vector images with large amounts of useless garbage (a similar issue has been discussed here before). Sometimes it is possible to simply delete this; if you post an eps version of your image I will try (I can't get your pdf version to convert to eps properly).

Ultimately, using Illustrator is like crossing the Misty Mountains by going through the Mines of Moria --- don't do it unless you have no other choice. Here is a 719 byte eps version of your image.

%!PS-Adobe-2.0 EPSF-2.0
%%Title: green_thing.eps
%%BoundingBox: -2 -2 382 382
/L{lineto} bind def
/M{moveto} bind def
/N{newpath} bind def
/R{rlineto} bind def
/vline{N 0 0 M 0 380 L stroke} bind def
/hline{N 0 0 M 380 0 L stroke} bind def
0.5 setlinewidth
0.75 1.0 0.61 setrgbcolor
N 160 20 M
80 0 R
2{0 20 R 40 0 R} repeat
2{0 40 R 20 0 R} repeat
0 100 R
2{-20 0 R 0 40 R} repeat
2{-40 0 R 0 20 R} repeat
-100 0 R
2{0 -20 R -40 0 R} repeat
2{0 -40 R -20 0 R} repeat
0 -100 R
2{20 0 R 0 -40 R} repeat
60 0 R
0 -20 R
40 0 R
closepath fill
0 0 0 setrgbcolor
18{20 0 translate vline} repeat
-360 0 translate
18{0 20 translate hline} repeat
0 -360 translate
N 0 0 M 0 380 L 380 380 L 380 0 L closepath stroke
showpage
%EOF

green thing

Ian Thompson
  • 43,767
1

When saving PDF files from Adobe Illustrator you can specify in the save dialog unter Adobe PDF Preset to use Smallest File Size. Use this for the files that go into production but keep another copy for editing. This also applies to EPS files saved from Illustrator.

enter image description here

  • 2
    Thank you Christian, but the .pdf above was already obtained with this setting. I have already found out that Illustrator saves other objects (probably, brushes and swatches, which go into "Document Overhead"), which make the file larger and are not excluded by the "Smallest file size" setting. I have found no way to get rid of these object from inside Illustrator, and you have to go to Acrobat Pro for that. However, in Inkscape it's all smooth and natural. – Dr_Zaszuś Apr 03 '15 at 09:08
  • I looked at your file with cpdf, a command-line tool for PDF processing, and managed to shrink it to 121kB. While it does have an option to remove unused code, it didn't seem to find the overhead. – Christian Lindig Apr 03 '15 at 09:34
1

If you already know what resolution you're going to show and print your document in, the raster graphics are fine. You are the master of your own destiny!

Keeping it in vector format means that whoever prints it or views it should be able to see it without any ugliness. In most cases the image is pixelated before it's viewed or printed anyway

Dr Xorile
  • 232