24

I'm converting an image from .png to .eps and it hugely increases the file size. Can anyone explain why this is, and how to prevent it increasing so much.

I'm using Unix convert: convert image.png image.eps

Thanks for any help

Tim
  • 1,221
  • 13
  • 23
Freddie
  • 1,657
  • 2
  • 15
  • 23

5 Answers5

47

Use level 3 postscript if you can. In general, level 3 will produce the smallest files. Level 2 provides the best compatibility, and works well with jpeg images. (see http://electron.mit.edu/~gsteele/pdf/)

convert fig.png eps3:fig.eps
rambalachandran
  • 1,631
  • 1
  • 15
  • 28
Georg Wachter
  • 471
  • 4
  • 2
  • When using Miktex with texify (but not pdf mode) you can include the resulting eps file using includegraphics. – Janosch Jul 09 '15 at 19:08
  • 3
    I got this error: `convert: unable to zip-compress image fig.eps @ error/compress.c/ZLIBEncodeImage/1280`. – warship Jan 09 '16 at 05:07
  • 3
    @warship: i got the same error, but it worked when i ran eps2 – rottweiler Jan 27 '16 at 18:10
  • @warship Did you manage to fix this error? I'm getting it too – Nubcake May 30 '17 at 20:12
  • Finally the working answer! This works in Mac OS X too with brew! This is the only answer that provides smallest size with decent resolution from all of the above. – Sunfloro Mar 07 '19 at 23:28
12

convert indeed blows up the file size because it stores the graphics data uncompressed. A better compression and smaller file size can be achieved by e.g. manually converting using gimp, or by doing

convert image.png image.pdf
pdftops -eps image.pdf

In my case, for example, this results in an eps file with a size of 0.3 MB instead of 5.2 MB (when using convert file.png file.eps directly).

fuenfundachtzig
  • 6,344
  • 11
  • 54
  • 77
  • 3
    This did not work for me. The image went from 659Kb (PNG) to 750Kb (PDF) to **16.4Mb (EPS)** even larger than using the direct `convert *.png to *.eps` which resulted in 12.8Mb. – Gabriel Jun 09 '14 at 19:22
  • 1
    Gimp worked fine for me. However, if you have a lot of files, Gimp will not be as easy as a command-line solution. – hadi Jan 08 '15 at 21:14
  • gimp is the only thing that preserved the details in my images perfectly. – dbliss Jun 23 '17 at 04:49
7

Converting a PNG file (designed for bitmap data) into an EPS (designed for vector data) is always going to result in a larger file size, as the EPS is effectively just wrapping an EPS data structure around the original image data (which it most likely won't store in anywhere near as effective a manner as a PNG file).

The correct solution is to store bitmaps as PNGs and vector graphics as EPS or SVG, etc. (i.e.: Use the appropriate file format for the content in question rather than attempting to impose a meaningless "one size fits all" approach.)

John Parker
  • 52,372
  • 11
  • 124
  • 125
  • 4
    For future reference I used "convert -density 300 myfig.png myfig.pdf" (the 300 is for a better quality), and then I used "pdftops -eps myfig.pdf". This process allowed me to create *.eps figures of size less than 0.5MB (before around 3-4MB ) and with a moderate quality. A little better that with the direct convert alone process. Maybe it's possible to improve the quality by increasing the density. – Ana S. H. Aug 24 '16 at 05:02
  • The solution mentioned by @AnaS.H. is what worked best for me, out of all those in this post. You should turn your comment into an answer Ana! – Gabriel Dec 12 '16 at 14:28
2

I had a similar problem and solved it using the -sample parameter:

convert image.png -sample 100 image.eps

and tweak the -sample value to fit your need.

Also see ImageMagick v6 Examples -- Resize or Scaling

N.B. The inverse (from EPS/PDF to PNG/JPG) can be tuned using -density.

Tim
  • 1,221
  • 13
  • 23
  • 1
    This works in reducing the size but the quality is so bad it's almost useless. To obtain a higher quality you're forced to increase the `sample` parameter and the .eps image ends up having the same large size as it would with the direct conversion. – Gabriel Jun 09 '14 at 19:26
  • Perfect! Worked like a charm. – Ekaba Bisong Nov 13 '18 at 20:38
1

It is possible that the problem is that the convert application you use just does not support embedding PNG into EPS. When using properly configured Adobe Acrobat Professional I newer got unexpectedly huge increase of the file size. But you should properly configure first your "PNG to PDF" conversion settings. Then you should export (or Save As) generated PDF as EPS from Acrobat.

Alexey Popkov
  • 8,995
  • 3
  • 40
  • 88