Convert PNG to EPS

If you are a LaTex user like me you will instantly recognize what I’m getting at here. LaTex does not work well with most of the popular image formats such as JPG, BMP, PNG or GIF. It does like encapsulated postscript images though (EPS). So if you want nice figures in your papers you can either use tools that can generate eps files, or convert.

I usually just go straight to EPS – most of Linux based graphing tools have support for either than or straight postscript which is also perfectly fine for LaTex. Between OpenOffice.org, Gnuplot, and the charting tools in KOffice I rarely need to convert anything. But the other day I was doing a batch of screenshots of an application and the default output format was PNG.

How do you convert from PNG to EPS? There are lots of ways, but since I was on ubuntu, I opted for using sam2p. It’s a small application that converts raster images into bunch of different formats. You probably won’t find it in a default installation so just do:

apt-get install sam2p

Note that you need to have universe enabled in your apt sources. Once you install it, the rest is easy:

sam2p Screenshot-1.png EPS: Screenshot-1.eps

First argument is the source image, second is the desired format followed by a colon, and the third is the desired name of the output file. Easy as pie. The only slight disadvantage of doing this is that you pay a considerable size penalty for this conversion:

Screenshot-1.png: 6.4KB
Screenhsot-1.eps: 20.0 KB

But that’s to be expected – after all we are goinf from tight binary image format to a textual postscript monstrosity. Note that you can cat the EPS file you will see nice coded segments composed of only ASCII characters. If you try to do that to a PNG file, you will see garbled binary mess and hear the system bell sound off once or twice (encountering the ASCII code for system bell in the output).

Related Posts:

  • Convert JPG and PNG to EPS on Windows
  • Convert PS and EPS images to JPEG
  • I have a thesis! Access Point must die!
  • Your perfect Linux Distro?
  • Text Dumping PDF files
  • Google goes Jabber
  • Run PNGOUT on all PNG Files in a Folder
  • XFN Icons
  • Fullmetal Southparked
  • So this is why GOTO is considered harmful!

  • 22 Responses to “Convert PNG to EPS”

    1. Sergejs LATVIA Mozilla Firefox Linux says: Reply to this comment

      Thank you very much :)
      I was searching for converting tool between PNG to EPS, you post helped me alot.

    2. Luke UNITED STATES Mozilla Firefox Windows says: Reply to this comment

      Glad I could help :mrgreen:

    3. Giordano ITALY Mozilla Firefox Linux says: Reply to this comment

      Thank you very much for the advice! I was lokking for such a tool :)

    4. Giordano ITALY Mozilla Firefox Linux says: Reply to this comment

      Thank you very much for the advice! I was looking for such a tool :)

    5. Chris UNITED KINGDOM Mozilla Firefox Linux says: Reply to this comment

      Two things that might help: ImageMagick has a ‘convert’ command that will translate between any two of over 100 different formats. That includes PNG, EPS, etc. I use this in a Makefile to convert any unsupported formats to PDF ready for inclusion in latex.

      Secondly, as you noticed the conversion process to EPS results in large files. If you use pdflatex you get PDF output, including automatically generated links in table of contents, citations etc., with the ‘hyperref’ package, and you can include native PNG and JPG without conversion to EPS. Native PDF can also be included which is supported as an export from many applications, and there’s eps2pdf and ps2pdf for all the older apps. It’s great.

    6. Luke UNITED STATES Mozilla Firefox Ubuntu Linux says: Reply to this comment

      Thanks for the tip. I think I was specifically using something that didn’t work nice with pdflatex – but yeah, I think this would work. :)

    7. Brett UNITED KINGDOM Mozilla Firefox Ubuntu Linux says: Reply to this comment

      Here is a little bash script I used to convert a folder full of png files into eps for latex. It was modified from here

      #!/bin/bash
       
      if [ ! -d ./eps_images ]; then mkdir ./eps_images; fi;
       
      # creates the eps image
      for f in *.png;
      do
          echo "Processing $f"
          sam2p $f EPS: ./eps_images/${f/.png}.eps
      done
    8. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux says: Reply to this comment

      Very nice! Thanks for posting it!

    9. Mats Rauhala FINLAND Mozilla Firefox Linux says: Reply to this comment

      Do notice however that ‘convert’ utility creates absurdly large images.
      3992 -rw-r–r– 1 masse masse 4079736 2008-05-08 12:07 0798116.convert.eps
      2496 -rw-r–r– 1 masse masse 2550945 2008-05-08 12:08 0798116.gimp.eps
      372 -rw-r–r– 1 masse masse 375691 2008-05-05 17:17 0798116.jpg
      See the difference?

      As a sidenote I tried to bzip multiple eps files, and got around 98% packing ratio.

    10. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux says: Reply to this comment

      Yeah, that’s true. That’s the major downside of this method.

    11. Naga Hyde UNITED STATES Internet Explorer Windows says: Reply to this comment

      I suspect you forgot to compress the eps with convert. Try either

      convert Screenshot-1.png eps2:Screenshot-1.eps

      or use eps3 for tighter compression. Without these it is indeed huge.

    12. Luke Maciak UNITED STATES Mozilla Firefox Windows says: Reply to this comment

      Ah, thanks for the tip!

    13. goodmami UNITED STATES Mozilla Firefox Linux says: Reply to this comment

      I tried this on Ubuntu Hardy 8.04, and I got an error that it couldn’t find some command (pngtopnm). I did
      apt-get install netpbm
      and that fixed it.

      Also, I tried both convert and sam2p, and here’s the file sizes (source image is here)

      -rw-r--r-- 1 goodmami goodmami 356K 2008-07-20 19:34 convert_eps2.eps
      -rw-r--r-- 1 goodmami goodmami 32K 2008-07-20 19:34 convert_eps3.eps
      -rw-r--r-- 1 goodmami goodmami 5.0M 2008-07-20 19:33 convert_eps.eps
      -rw-r--r-- 1 goodmami goodmami 30K 2008-07-20 17:40 italophone_map.png
      -rw-r--r-- 1 goodmami goodmami 23K 2008-07-20 19:36 sam2p_eps2.eps
      -rw-r--r-- 1 goodmami goodmami 23K 2008-07-20 19:29 sam2p_eps.eps

      note that convert is horrible. The file sizes are generally much larger than the original (with the exception of eps3). eps2 did not even fully render the image. sam2p, however, had file sizes even smaller than the original (note that the image is very simple… not a photograph or anything). sam2p allowed eps and eps2 commands, but there was no difference.

    14. Swaprava INDIA Mozilla Firefox Windows says: Reply to this comment

      I know Linux users don’t like Windows, but since I’m using it and still want to convert png to ps, how should I go about it?

    15. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux says: Reply to this comment

      @Swaprava: I think that OpenOffice.org has a functionality to export to EPS. I used it in the past to create simple drawings and flowcharts for some of my papers. I think you can just insert your image into a OOo Writer, fiddle around with margins and save the page as EPS.

      Either that or try Gimp (the open source Photoshop alternative) – it works pretty well on Windows. Not the most intuitive tool, but it gets to job done.

    16. Chris UNITED KINGDOM Mozilla Firefox Ubuntu Linux says: Reply to this comment

      Swaprava: imagemagick is available on Windows too. link

    17. Adam UNITED KINGDOM Mozilla Firefox Ubuntu Linux says: Reply to this comment

      Another note, sometimes transparency in a PNG causes problems. Using GIMP to get rid of it before converting to EPS works well, and it can also be used to crop the original image as well. Try using eps2 or eps3 as well as plain eps, for me some types worked better on some files than others so a bit of trial-and-error was needed.

    18. pavel UNITED STATES Mozilla Firefox Linux says: Reply to this comment

      Well done, thanks for pointing this out.

    19. cesar CANADA Mozilla Firefox Ubuntu Linux says: Reply to this comment

      Great post… Fight for a long time for reducing EPS size by converting to greyscale… tried Convert … but in a sea of options is sometimes difficult to find what i was looking for.

      BTW… I have the following problem…

      EPS is great for generating plots… but sometimes my EPS gets HUGE when the database is biiiig… is there any way to reduce the size of the EPS in such a way that if I print the plot in a paper it still looks good? (I mean using a EPS conversion mechanism not by scattering my datapoints)

      Thanks man for your posts… have been useful more than once

    20. ernest POLAND Mozilla Firefox Ubuntu Linux says: Reply to this comment

      Thank you very much! It’s very helpful for me.

    21. Breciox BRAZIL Mozilla Firefox Ubuntu Linux says: Reply to this comment

      Good tip dude, I appreciate very much :)

    Leave a Reply