Convert PS and EPS images to JPEG

The reason why I post stuff like this here is twofold. Firstly (is that even a word?), I forget. Chances are that in 3 months I will need this shit again, and won’t remember the exact syntax, or the name of the tool I used. So instead of googling for it, I can just search through my blog archives.

Secondly, chances are that there are quite a few intermediate or beginner latex users out there who may or may not find this useful.

Here is the scenario: you created a beautiful Latex document. In fact it is so awesome that someone approaches you and asks you to send them that incredibly cool chart or figure you used in your paper. So you send the person the eps/ps file and they can’t open it.

The proper raction that should be taken in such situation is of course repeatedly whacking said person on the head with a blunt object until they get a clue. Sadly forcible clue insertion is not always an option, so every once in a while you will need to convert your images into some more luser friendly format.

You can convert any ps or eps file into a jpeg using ghostscript:

gs -sDEVICE=jpeg -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r300 -sOutputFile=myfile.jpg myfile.eps

This method has one flaw. It produces humongous files. Depending on the eps file you may get something like 2000×3000 pixels which is slightly on the insane side. Also the file size of the JPG will be about 10 times that of the eps.

We will now need to trim and resize the file using some Image Magic tools:

mogrify -trim -resize 800x600 myfile.jpg

Obviously you can put your own dimension instead of the 800×600. Mogrify will resize the image, and also cut down the size of the file to a manageable level. Still, in most cases files obtained using this method were bigger than the eps files used to produce them. It’s best to simply use your photo editing tool (gimp?) and re-export the image/chart to a conventional image format. It will probably yield much better results than this conversion.

On the other hand, if a ps/eps is all you have, this might be useful.

Related Posts:

  • Convert PNG to EPS
  • Convert JPG and PNG to EPS on Windows
  • Poor Man’s Steganography
  • How good are Digital Pens?
  • Latex: Rotate Inserted Images
  • Text Dumping PDF files
  • Download Website for Offline Reading with Wget
  • Batch Upload Images to ImageShack using Perl
  • Those pesky PDF files
  • Super Heroines

  • 10 Responses to “Convert PS and EPS images to JPEG”

    1. Gravatar Srinivas D INDIA Says: Reply to this comment

      Hi,
      I am using Ubuntu Linux I am creating ps files but I need in jpeg format
      I used the below conversion to convert ps to jpeg, but I created only one
      image but the ps files has 12 figures.
      Could you please suggest me how to solve this problem
      ” gs -sDEVICE=jpeg -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r300 -sOutputFile=myfile.jpg myfile.eps”
      Thanking you
      D Srinivas

      Posted using Internet Explorer Internet Explorer 7.0 on Windows Windows XP
    2. Gravatar Luke Maciak UNITED STATES Says: Reply to this comment

      Are the figures on separate pages? Then you can split the original ps file with:

      gs -r300 -sDEVICE=djet500 -sOutputFile=myfile.%03d.ps -dNOPAUSE myfile.ps -c quit

      This will produce bunch of files named myfile001.ps, myfile002.ps, myfile003.ps and etc - one file per page.

      Take these files and run them through the stuff above and you should be good. ) Let me know if that helps.

      If this doesn’t work (some ps files just don’t cooperate with this method_ I’d just recommend to open the ps file, and take a screenshot of each chart with something like Ksnapshot which lets you capture just a selected region of the screen.

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.12 on Windows Windows XP
    3. Gravatar Srinivas INDIA Says: Reply to this comment

      Dear Sir,
      I used “gs -r300 -sDEVICE=pswrite -sOutputFile=ds%03d.ps -dNOPAUSE test.ps -c quit” to convert ps file which contains many images in that and
      it created all individual figures
      Now I am trying to convert back these ps files to jpg format
      But I am unable to do it
      I am using presently

      “gs -sDEVICE=jpeg -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r300 -sOutputFile=jds%03d.jpg ds%03d.ps”

      It is not converting to jpg format
      Could you please suggest me how to do it
      Thanking you sir
      D Srinivas

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.12 on Windows Windows XP
    4. Gravatar Luke Maciak UNITED STATES Says: Reply to this comment

      I don’t think it’s recognizing the “ds%03d.ps” as an input file name. I don’t think you can use the %03d notation this way. Have you tried running the command individually on each ps file?

      Alsternatively, you can try this:

      for f in $(ls *.ps); do
      gs -sDEVICE=jpeg -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r300 -sOutputFile=$f.jpg $f
      done

      This will loop through all the .ps files in the current directory and create a jpeg for each of them.

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.12 on Ubuntu Linux Ubuntu Linux
    5. Gravatar Srinivas INDIA Says: Reply to this comment

      Dear Sir
      I am thankful for your reply, which helped me very much
      I tried on individual file, it worked well,
      Now I success with this command
      Thanking you sir
      D Srinivas

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.12 on Windows Windows XP
    6. Gravatar Luke Maciak UNITED STATES Says: Reply to this comment

      Glad I could help. )

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.12 on Ubuntu Linux Ubuntu Linux
    7. Gravatar Srinivas INDIA Says: Reply to this comment

      Dear Sir
      I am working with those commands fine, Now what the images created
      are having very large file size
      Could you please suggest me to reduce the file size of jpeg images
      Because I am creating at a time 12 images giving a total size of
      nearly 20 MB
      So, Please could you please suggest me to reduce the file size
      Thanking you sir
      D Srinivas

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.12 on Windows Windows XP
    8. Gravatar Luke Maciak UNITED STATES Says: Reply to this comment

      Did you do the mogrify step from above? Set the resolution to something smaller (like 320×320 for example) and see if that drops down the size.

      I’d try -sample instead of -resize option - this way it will resample the image hopefully resulting in much greater size reduction.

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.12 on Ubuntu Linux Ubuntu Linux
    9. Gravatar Srinivas INDIA Says: Reply to this comment

      Dear Sir
      I am thankful to your reply
      But In my computer I donot have mogrify command
      Please kindly suggest me
      Thanking you sir
      D Srinivas

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.12 on Windows Windows XP
    10. Gravatar Luke Maciak UNITED STATES Says: Reply to this comment

      It’s part of the Image Magic package. You’re on Ubuntu, right?

      sudo aptitude install imagemagic

      That should install mogrify and bunch of other useful image manipulation tools.

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.12 on Ubuntu Linux Ubuntu Linux

    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <pre lang=""> <em> <i> <strike> <strong>

    [Quote selected]